Class MockPreferenceService

Service to manage preferences including, among others, getting and setting preference values as well as listening to preference changes.

Depending on your use case you might also want to look at createPreferenceProxy with which you can easily create a typesafe schema-based interface for your preferences. Internally the proxy uses the PreferenceService so both approaches are compatible.

Implements

Constructors

Properties

isReady: true = true

Indicates whether the service has successfully initialized. Will be true when the ready Promise resolves.

onPreferenceChanged: Event<PreferenceChange> = ...

Registers a callback which will be called whenever a preference is changed.

onPreferencesChanged: Event<PreferenceChanges> = ...

Registers a callback which will be called whenever one or more preferences are changed.

ready: Promise<void> = ...

Promise indicating whether the service successfully initialized.

Methods

  • Retrieve the stored value for the given preference.

    Type Parameters

    • T

    Parameters

    • preferenceName: string

      the preference identifier.

    Returns undefined | T

    the value stored for the given preference when it exists, undefined otherwise.

  • Retrieve the stored value for the given preference.

    Type Parameters

    • T

    Parameters

    • preferenceName: string

      the preference identifier.

    • defaultValue: T

      the value to return when no value for the given preference is stored.

    Returns T

    the value stored for the given preference when it exists, otherwise the given default value.

  • Retrieve the stored value for the given preference and resourceUri.

    Type Parameters

    • T

    Parameters

    • preferenceName: string

      the preference identifier.

    • defaultValue: T

      the value to return when no value for the given preference is stored.

    • resourceUri: string

      the uri of the resource for which the preference is stored. This used to retrieve a potentially different value for the same preference for different resources, for example files.encoding.

    Returns T

    the value stored for the given preference and resourceUri when it exists, otherwise the given default value.

  • Tries to split the given preference identifier into the original OverridePreferenceName attributes with which this identifier was created. Returns undefined if this is not possible, for example when the given preference identifier was not generated by overridePreferenceName.

    This method is checked when resolving preferences. Therefore together with "overridePreferenceName" this can be used to handle specialized preferences, e.g. "[markdown].editor.autoIndent" and "editor.autoIndent".

    Parameters

    Returns undefined | OverridePreferenceName

    the OverridePreferenceName which was used to create the given preferenceName if this was the case, undefined otherwise.

  • Retrieve the stored value for the given preference and resourceUri.

    Type Parameters

    • T

    Parameters

    • preferenceName: string

      the preference identifier.

    • Optional defaultValue: T

      the value to return when no value for the given preference is stored.

    • Optional resourceUri: string

      the uri of the resource for which the preference is stored. This used to retrieve a potentially different value for the same preference for different resources, for example files.encoding.

    Returns {
        configUri?: URI;
        value?: T;
    }

    an object containing the value stored for the given preference and resourceUri when it exists, otherwise the given default value. If determinable the object will also contain the uri of the configuration resource in which the preference was stored.

    • Optional configUri?: URI
    • Optional value?: T
  • Determines and applies the changes necessary to apply value to either the resourceUri supplied or the active session. If there is no setting for the preferenceName, the change will be applied in user scope. If there is a setting conflicting with the specified value, the change will be applied in the most specific scope with a conflicting value.

    Returns Promise<void>