Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom file associations #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ Multiple languages supported.

<hr/>

### 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.

<hr/>

### dotenv-vault (included but optional)

Manage your secrets using <strong>dotenv-vault</strong>'s all-in-one toolkit. Say goodbye to scattered secrets across multiple platforms and tools.
Expand Down
19 changes: 15 additions & 4 deletions lib/fileAssociations.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Other"
],
"activationEvents": [
"*"
"*",
"onLanguage:dotenv"
],
"main": "./extension.js",
"contributes": {
Expand Down Expand Up @@ -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"
}
}
},
Expand Down