Skip to content

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

Closed

Description

@rebornix
  • 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.

Activity

  1. 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
  2. added
    bug
    on Jul 26, 2016
  3. jrieken commented on Jul 27, 2016

    @jrieken
    Contributor

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

  4. rebornix commented on Jul 27, 2016

    @rebornix
    ContributorAuthor

    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.

  5. jrieken commented on Jul 27, 2016

    @jrieken
    Contributor

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

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

  6. aeschli commented on Jul 27, 2016

    @aeschli
    Contributor

    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.

  7. rebornix commented on Jul 27, 2016

    @rebornix
    ContributorAuthor

    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?

  8. aeschli commented on Jul 27, 2016

    @aeschli
    Contributor

    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.

  9. jrieken commented on Jul 27, 2016

    @jrieken
    Contributor

    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?

  10. aeschli commented on Jul 27, 2016

    @aeschli
    Contributor

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

  11. locked and limited conversation to collaborators on Nov 18, 2017
  12. added a commit that references this issue on Sep 6, 2026
    0580e1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apibugverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions