-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Allow extensions to set configuration options. #1396
Comments
@mitchdenny You can also use the extension state for storage (https://code.visualstudio.com/docs/extensionAPI/vscode-api#ExtensionContext) |
Thanks @jrieken. I'll look into that in the meantime. Are you considering allowing extensions to write settings or is using extension state the better approach for this kind of setting? |
Not decided yet. The model of today is that only the user can modify settings and there is lot of good about that, but also see some shortcomings... The extension state is meant for remembering a user choice, store some installing path etc. This also includes your use-case. Since it's a little touchy (collecting telemetry data) I can understand that you want a more prominent option to unset something like that. |
Thanks for getting back to me. Appreciate it. |
Closing as we believe the current story isn't too bad. User manually editor configuration options and extensions can persist settings etc globally/locally |
We have decided to open up that way - giving extensions the power to modify the configuration outweighs the risks. |
@egamma, @aeschli - I wonder if I should implement a restriction wrt setting configurations. For me it makes sense that you cannot write a setting which isn't defined anywhere, like |
Given that our settings are just key-value pairs, why would we care about settings like 'foo.bar'. |
Because they end up in a file which is supposed to be human readable, if an extension by accident fills it up with random stuff your configuration is effectively lost. |
There is a challenge with this. Generally, our configuration is flat key-value pairs. The catch is that keys can be dot-separated and that the configuration is an object-tree along those dots. For instance, the setting For reading, we don't differentiate this. You can do |
Btw I would find it a good thing if an extension could actually write to extensions it does not contribute because this opens the door for a whole new family of extensions that could provide added value for changing settings (e.g. toggle core settings via command palette or ask the user if he is a tabs user or not and then make all the settings changes to disable or enable tabs). As for writing settings, not sure. I think the main use case is to write a value for a setting that shows up in user settings. If there is Now, I am not sure if you could enforce this at all given that in the end all of these things end up being one large object. Unrelated: would this API take into consideration that there are global settings and workspace settings? |
There is a misunderstanding. Yes, I do want to allow extensions to write any setting - given it exists. That is the foobar extension can reconfigure search/tabs/etc but it cannot introduce a new config option. When thinking of key-value-pairs, you can set the value of any key but you cannot introduce a new key. Only the static contribution point in package.json can do that.
Yes. Current thinking is that there The problem with writing is that I'd like to know if for a given |
Right now the configuration service doesn't know anything about the configuration schemas, but it looks like it should. |
That would be deluxe ;-) Similar to other places in the API we would apply a change always locally, send it to the main side, and update the extension side according to what it did (we do the same for instance with editor selection). |
Yes, +1 for not introducing new keys to the setting. I also see the issue with validation so for sure, the API needs to run the same validation checks we see in the editor and reject invalid updates. There is another complexity: today we have The global vs workspace configuration change is tricky because an extension might only write to the global config but the user might have workspace config that actually overwrites this setting. |
I knew that but the |
@jrieken also ugly, but less hardcoded: this all happens in https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/services/configuration/common/model.ts#L54 and the idea is that any JSON file in the |
Rethinking how this could work for task and debug I think these are new Now, from an extension point of view I also think that this should be made very explicit in the API: If an extension can change launch configurations, there should be a namespace in the API to do so (same for tasks). Imho we should not implicitly write to |
Keys in the |
Quick question! There are several comments in this thread that suggest we shouldn't be having settings that don't exist in the package.json. Currently we assumed this was a feature, eg. having "hidden" settings - we have a couple of settings that we (extension devs) turn on (such as logging traffic to the language service to a file, and I was thinking about feature toggles we don't want to show to users in the settings file/completion yet). Are we just taking advantage of a lack of validation here and we should stop using settings that aren't declared in the package.json? |
@jrieken I added support to write to
Let me know if more is needed from the workbench. |
Does it mean it's asymmetric? So when I have |
@jrieken today it seems random who is winning in such a case. in my testing the I think when merging settings in our config model we should first take all settings from |
Pushed a change to ensure that any value in |
@bpasero I just tried this and seems to work great! It would be lovely if we could format the launch.json / tasks.json / settings.json after editing it. Here is a small gif where I am adding a new configuration using the API after the hello world command |
@isidorn is that changing an existing launch.json or creating a brand new one? |
@bpasero that is changing an existing |
@isidorn actually I can reproduce and this seems to happen when you pass in a complex object to @aeschli method The formatting seems to be ok'ish preserved if you just change simple key-value pairs, but not for such larger objects. As a workaround you could just get the configuration and set it fully because then I am applying it using |
@bpasero thanks for the workaround! |
I've got an extension that I'm currently adding telemetry too so that I can better understand how people are using it, however I want to give users an easy way to opt out of this telemetry collection. My initial thoughts were that I would display a quick pick with two options (agree or disagree) and that I would then store their choice for later executions.
However, it looks like the configuration API for extensions doesn't support the option to set a configuration value. It would be great if I could do something like this:
I'm sure other extensions would find this useful as well to help guide users to setting up sensitive defaults.
The text was updated successfully, but these errors were encountered: