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

[Configuration] Get configuration doesn't return default value if not found. #9731

Closed
rebornix opened this issue Jul 26, 2016 · 8 comments
Closed
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@rebornix
Copy link
Member

  • VSCode Version: 1.4.0-Insider
  • OS Version: Windows 10 x64

Steps to Reproduce:

  1. Add a new boolean option to contribution list of an extension
  2. 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.

@rebornix rebornix 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. Jul 26, 2016
@rebornix rebornix mentioned this issue Jul 26, 2016
10 tasks
@kieferrm kieferrm added bug Issue identified by VS Code Team member as probable bug api labels Jul 26, 2016
@jrieken
Copy link
Member

jrieken commented Jul 27, 2016

@rebornix How did you define the configuration property? If the default is defined to be false then the behaviour is expected

@rebornix
Copy link
Member Author

rebornix commented Jul 27, 2016

@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
Copy link
Member

jrieken commented Jul 27, 2016

Understood. It seems like the value is set to null when not being defined which defeats this check.

@aeschli Did we change the default value when the definition doesn't contain a value?

@jrieken jrieken added this to the July 2016 milestone Jul 27, 2016
@aeschli
Copy link
Contributor

aeschli commented 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.

@aeschli aeschli assigned aeschli and unassigned jrieken Jul 27, 2016
@rebornix
Copy link
Member Author

@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?

@aeschli
Copy link
Contributor

aeschli commented 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
Copy link
Member

jrieken commented Jul 27, 2016

@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?

@jrieken jrieken reopened this Jul 27, 2016
@aeschli
Copy link
Contributor

aeschli commented Jul 27, 2016

Looked at it with Joh, he ran again in the number case. Tried again, an all seems fine now.

@aeschli aeschli closed this as completed Jul 27, 2016
@jrieken jrieken added the verified Verification succeeded label Jul 28, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

4 participants