diff --git a/README.md b/README.md
index 84adbca..d018396 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,24 @@ Multiple languages supported.
+### Custom File Associations for dotenv Files
+
+To define custom file associations for `dotenv` files in `settings.json`, use the `dotenv.files.associations` setting. This allows you to associate custom file patterns with the `dotenv` language, enabling syntax highlighting, auto-cloaking, auto-completion, and in-code secret peeking for those files.
+
+For example, to associate all files in a `.env.d` directory as `dotenv` files, add the following to your `settings.json`:
+
+```json
+{
+ "dotenv.files.associations": {
+ "**/.env.d/*": "dotenv"
+ }
+}
+```
+
+This feature enhances flexibility in managing environment variables across different projects and setups.
+
+
+
### dotenv-vault (included but optional)
Manage your secrets using dotenv-vault's all-in-one toolkit. Say goodbye to scattered secrets across multiple platforms and tools.
diff --git a/lib/fileAssociations.js b/lib/fileAssociations.js
index 2171cf7..33bbb25 100644
--- a/lib/fileAssociations.js
+++ b/lib/fileAssociations.js
@@ -1,9 +1,20 @@
-const settings = require('./settings')
+const vscode = require('vscode');
+const settings = require('./settings');
const run = function () {
- settings.populateFileAssociations()
+ // Retrieve custom file associations from settings.json
+ const customAssociations = vscode.workspace.getConfiguration().get('dotenv.files.associations');
- return true
+ // Populate default file associations
+ settings.populateFileAssociations();
+
+ // Merge custom file associations with default ones
+ const fileAssociations = vscode.workspace.getConfiguration('files');
+ for (const [pattern, language] of Object.entries(customAssociations)) {
+ fileAssociations.update('associations', { ...fileAssociations.get('associations'), [pattern]: language }, vscode.ConfigurationTarget.Global);
+ }
+
+ return true;
}
-module.exports.run = run
+module.exports.run = run;
diff --git a/package.json b/package.json
index a86e85b..37097f4 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,8 @@
"Other"
],
"activationEvents": [
- "*"
+ "*",
+ "onLanguage:dotenv"
],
"main": "./extension.js",
"contributes": {
@@ -60,6 +61,12 @@
"type": "string",
"default": "█",
"description": "Change the icon of the cloak for your .env files"
+ },
+ "dotenv.files.associations": {
+ "scope": "resource",
+ "type": "object",
+ "default": {},
+ "description": "Custom file associations for dotenv files"
}
}
},