0

Currently I am trying to write an extension that allows me to dynamically change the workspace filter by adding/removing/modifying entries in the files.exclude configuration element and storing it in the workspace settings.

Running a command like this, e.g. to modify a string or array based configuration works as intended:

const config = vscode.workspace.getConfiguration();
config.update('editor.fontSize', 14, false); -> works

But I just can't wrap my head around how to modify an object based configuration like files.exclude. I tried different approaches but always got an error saying that I am accessing an element that does not exist.

config.update('files.exclude.TestXYZ', false, false); -> doesn't work
config.update('TestXYZ', false, false); -> doesn't work

Hardcoding an object in advance and using this as new value for the configuration works

let settings = { "*.html": true, "*.css": true };
config.update('files.exclude', settings, false); -> works, but isn't what I need

but in order to write a configurable workspace filter I need to add/remove values from the filter list dynamically.

In addition to that (but not as important): I also can't manage to "read" the current values of files.exclude in a way that I can work with them. I always get a Proxy object and I'm not that of a pro in typescript tbh.

The initial idea was to read the configuration, make my modifications and save it back but after trying for hours I would be OK to overwrite them entirely as long as it works.

  • I guess this is really more of a TS question. Does something like this help? https://stackoverflow.com/questions/12710905/how-do-i-dynamically-assign-properties-to-an-object-in-typescript – Gama11 Feb 18 '20 at 08:51
  • Also: https://stackoverflow.com/questions/40201970/enumerate-properties-on-an-object – Gama11 Feb 18 '20 at 08:52
  • @Gama11: Thanks a lot, it worked :D – rohrbrecher Feb 19 '20 at 05:54

1 Answers1

0

With the helpful links by @Gama11 I was able to achieve the result I wanted:

const config = vscode.workspace.getConfiguration(); 
var excludeList: {[k: string]: boolean} = {}; 
excludeList[*.html] = true; 
excludeList[*.css] = true;
config.update('files.exclude', excludeList, false);

With this I can dynamically change the excludeList and update the config accordingly.