Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface WorkspaceConfiguration

Represents the configuration. It is a merged view of

  • Default Settings
  • Global (User) Settings
  • Workspace settings
  • Workspace Folder settings - From one of the Workspace Folders under which requested resource belongs to.
  • Language settings - Settings defined under requested language.

The effective value (returned by get) is computed by overriding or merging the values in the following order.

`defaultValue` (if defined in `package.json` otherwise derived from the value's type)
`globalValue` (if defined)
`workspaceValue` (if defined)
`workspaceFolderValue` (if defined)
`defaultLanguageValue` (if defined)
`globalLanguageValue` (if defined)
`workspaceLanguageValue` (if defined)
`workspaceFolderLanguageValue` (if defined)

Note: Only object value types are merged and all other value types are overridden.

Example 1: Overriding

defaultValue = 'on';
globalValue = 'relative'
workspaceFolderValue = 'off'
value = 'off'

Example 2: Language Values

defaultValue = 'on';
globalValue = 'relative'
workspaceFolderValue = 'off'
globalLanguageValue = 'on'
value = 'on'

Example 3: Object Values

defaultValue = { "a": 1, "b": 2 };
globalValue = { "b": 3, "c": 4 };
value = { "a": 1, "b": 3, "c": 4 };

Note: Workspace and Workspace Folder configurations contains launch and tasks settings. Their basename will be part of the section identifier. The following snippets shows how to retrieve all configurations from launch.json:

// launch.json configuration
const config = workspace.getConfiguration('launch', vscode.workspace.workspaceFolders[0].uri);

// retrieve values
const values = config.get('configurations');

Refer to Settings for more information.

层级

  • WorkspaceConfiguration

Indexable

[key: string]: any

Readable dictionary that backs this configuration.

索引

Methods(4)

Methods(4)

get

  • get<T>(section: string): undefined | T
  • get<T>(section: string, defaultValue: T): T
  • Return a value from this configuration.

    Type parameters

    • T

    Parameters

    • section: string

      Configuration name, supports dotted names.

    Returns undefined | T

    The value section denotes or undefined.

  • Return a value from this configuration.

    Type parameters

    • T

    Parameters

    • section: string

      Configuration name, supports dotted names.

    • defaultValue: T

      A value should be returned when no value could be found, is undefined.

    Returns T

    The value section denotes or the default.

has

  • has(section: string): boolean
  • Check if this configuration has a certain value.

    Parameters

    • section: string

      Configuration name, supports dotted names.

    Returns boolean

    true if the section doesn't resolve to undefined.

inspect

  • inspect<T>(section: string): undefined | { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T; workspaceFolderValue?: T; defaultLanguageValue?: T; globalLanguageValue?: T; workspaceLanguageValue?: T; workspaceFolderLanguageValue?: T; languageIds?: string[] }
  • Retrieve all information about a configuration setting. A configuration value often consists of a default value, a global or installation-wide value, a workspace-specific value, folder-specific value and language-specific values (if WorkspaceConfiguration is scoped to a language).

    Also provides all language ids under which the given configuration setting is defined.

    Note: The configuration name must denote a leaf in the configuration tree (editor.fontSize vs editor) otherwise no result is returned.

    Type parameters

    • T

    Parameters

    • section: string

      Configuration name, supports dotted names.

    Returns undefined | { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T; workspaceFolderValue?: T; defaultLanguageValue?: T; globalLanguageValue?: T; workspaceLanguageValue?: T; workspaceFolderLanguageValue?: T; languageIds?: string[] }

    Information about a configuration setting or undefined.

update

  • update(section: string, value: any, configurationTarget?: null | boolean | ConfigurationTarget, overrideInLanguage?: boolean): Thenable<void>
  • Update a configuration value. The updated configuration values are persisted.

    A value can be changed in

    Note: To remove a configuration value use undefined, like so: config.update('somekey', undefined)

    throws

    error while updating - configuration which is not registered. - window configuration to workspace folder - configuration to workspace or workspace folder when no workspace is opened. - configuration to workspace folder when there is no workspace folder settings. - configuration to workspace folder when WorkspaceConfiguration is not scoped to a resource.

    Parameters

    • section: string

      Configuration name, supports dotted names.

    • value: any

      The new value.

    • Optional configurationTarget: null | boolean | ConfigurationTarget

      The configuration target or a boolean value. - If true updates Global settings. - If false updates Workspace settings. - If undefined or null updates to Workspace folder settings if configuration is resource specific, otherwise to Workspace settings.

    • Optional overrideInLanguage: boolean

      Whether to update the value in the scope of requested languageId or not. - If true updates the value under the requested languageId. - If undefined updates the value under the requested languageId only if the configuration is defined for the language.

    Returns Thenable<void>

友链:VS Code 中文文档 | VS Code 官网文档 | VS Code 扩展市场

Generated by TypeDoc. Maintained by 洛竹