You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Configuration] Get configuration doesn't return default value if not found. #9731
Add a new boolean option to contribution list of an extension
Run/debug the extension, try fetch the configure by vscode.workspace.getConfiguration("section").get("optionName", undefined)
If user doesn't set a value for this config in his/her settings.json, the return result of this expression should be undefined. While what we get is false.
If the config is defined as number, this expression will return null. If user sets this config explicitly, we can get the correct value.
BTW, it seems we don't have a chance to know whether a Code config, for example editor.tabSize, is set by User or Workspace or just default value. It's a potential feature request.
changed the title [-][Configuration] Get configuration doesn't return default value if not found.```[/-][+][Configuration] Get configuration doesn't return default value if not found.[/+]on Jul 26, 2016
Johannes Rieken (@jrieken) the thing is I didn't define its default value. A good proof is when we define a Number type configuration and don't add default value for it, we get null, it's not even a number.
I'm not aware of any recent changes, but there's a bug that we are missing the default for 'number' here.
I'll fix this but IMO a default value should always be set in the default configuration settings.
Martin Aeschlimann (@aeschli) Once you fix the the number default value, the second parameter defaultValue of vscode.workspace.getConfiguration("section").get("optionName", undefined) no longer works as there is always a value in Code, right? Besides, I'd like to set default value for all configs while implementing extensions, but if I do that, I'll never know where the configuration is from. Seems we simply merged Code default config, Extension default config, User setting and Workspace setting.
The reason I want to know the source of the config is that we have overlap between Vim and Code configuration. For example, vim.tabstop is totally the same as editor.tabSize from Code. We want to know if user sets vim.tabstop explicitly, if so we use vim.tabstop otherwise we still use editor.tabSize. But a default value makes it impossible as we always get a value from vim.tabstop through API. What do you think or any advice?
The 'defaultValue' parameter in WorkspaceConfiguration.get is useful if the key doesn't exist at all (e.g. if you access settings of an extension that is not present). No change for existing configurations: we already had the default value; it was just wrong for 'number', as you found out.
At the moment we don't have any API that would tell you where an option is defined (default, user or workspace). We were planning on adding such an API. We have no issue yet, please file one and we plan it.
Martin Aeschlimann (@aeschli) There is still an issue here in which the default for not having a default is null but the logic expects undefined for that. Since null is a valid json value but undefined isn't that's IMO the only value I can check for?
Activity
[-][Configuration] Get configuration doesn't return default value if not found.```[/-][+][Configuration] Get configuration doesn't return default value if not found.[/+]jrieken commentedon Jul 27, 2016
Peng Lyu (@rebornix) How did you define the configuration property? If the default is defined to be
falsethen the behaviour is expectedrebornix commentedon Jul 27, 2016
Johannes Rieken (@jrieken) the thing is I didn't define its default value. A good proof is when we define a Number type configuration and don't add default value for it, we get
null, it's not even a number.jrieken commentedon Jul 27, 2016
Understood. It seems like the value is set to
nullwhen not being defined which defeats this check.Martin Aeschlimann (@aeschli) Did we change the default value when the definition doesn't contain a value?
aeschli commentedon Jul 27, 2016
I'm not aware of any recent changes, but there's a bug that we are missing the default for 'number' here.
I'll fix this but IMO a default value should always be set in the default configuration settings.
rebornix commentedon Jul 27, 2016
Martin Aeschlimann (@aeschli) Once you fix the the number default value, the second parameter
defaultValueofvscode.workspace.getConfiguration("section").get("optionName", undefined)no longer works as there is always a value in Code, right? Besides, I'd like to set default value for all configs while implementing extensions, but if I do that, I'll never know where the configuration is from. Seems we simply merged Code default config, Extension default config, User setting and Workspace setting.The reason I want to know the source of the config is that we have overlap between Vim and Code configuration. For example,
vim.tabstopis totally the same aseditor.tabSizefrom Code. We want to know if user setsvim.tabstopexplicitly, if so we usevim.tabstopotherwise we still useeditor.tabSize. But a default value makes it impossible as we always get a value fromvim.tabstopthrough API. What do you think or any advice?aeschli commentedon Jul 27, 2016
The 'defaultValue' parameter in WorkspaceConfiguration.get is useful if the key doesn't exist at all (e.g. if you access settings of an extension that is not present). No change for existing configurations: we already had the default value; it was just wrong for 'number', as you found out.
At the moment we don't have any API that would tell you where an option is defined (default, user or workspace). We were planning on adding such an API. We have no issue yet, please file one and we plan it.
jrieken commentedon Jul 27, 2016
Martin Aeschlimann (@aeschli) There is still an issue here in which the default for not having a default is
nullbut the logic expectsundefinedfor that. Sincenullis a valid json value butundefinedisn't that's IMO the only value I can check for?aeschli commentedon Jul 27, 2016
Looked at it with Joh, he ran again in the number case. Tried again, an all seems fine now.
fixes microsoft#9731: [Configuration] Get configuration doesn't retur…