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:

  1. defaultValue (if defined in package.json otherwise derived from the value's type)
  2. globalValue (if defined)
  3. workspaceValue (if defined)
  4. workspaceFolderValue (if defined)
  5. defaultLanguageValue (if defined)
  6. globalLanguageValue (if defined)
  7. workspaceLanguageValue (if defined)
  8. 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.

Hierarchy

  • WorkspaceConfiguration

Indexable

[key: string]: any

Readable dictionary that backs this configuration.

Index

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>

Generated by TypeDoc. Maintained by 紫升

Links: 搜外友链, 69中文网