I want to create a VSCode extension, which allows me to hide certain files in the File Explorer using Extension Settings.
My status quo looks roughly like this:
package.json
{
"contributes": [
"configuration": {
"properties": {
"<extension-name>.hideResultFiles": {
"title": "Hide result files from File Explorer",
"type": "boolean",
"default": false
}
}
}
]
}
extension.ts
export function activate(context: vscode.ExtensionContext) {
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration("<extension-name>.hideResultFiles")) {
updateFileExplorerExcludes()
};
});
}
// Process extension file exclusions
async function updateFileExplorerExcludes() {
const config = vscode.workspace.getConfiguration()
var excludeList: { [k: string]: boolean } = {};
if (config.has("<extension-name>.hideResultFiles")) {
if (config.get("<extension-name>.hideResultFiles")) {
excludeList["**/*.outA"] = true;
excludeList["**/*.outB"] = true;
}
}
// apply excluded files/folders
config.update("files.exclude", excludeList, vscode.ConfigurationTarget.Workspace)
}
This works. The downside is that all the excludes are added explicitly to settings.json
{
"files.exclude": {
"**/*.outA": true,
"**/*.outB": true
}
}
How do I have to modify my code so that the excludes are not added explicitly to settings.json
, but rather only the setting itself is added, and the excludes are handled internally?
Desired look of settings.json
:
{
"<extension-name>.hideResultFiles": true
}