src/vs/platform/configuration/common/configuration.ts
358 LOC · 315 covered · 43 uncovered · 57 ranges · 9810 concepts · 28 introducers · 5042 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
configuration.ts ×12
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { assertNever } from '../../../base/common/assert.js';
import { IStringDictionary } from '../../../base/common/collections.js';
import { Event } from '../../../base/common/event.js';
import * as types from '../../../base/common/types.js';
import { URI, UriComponents } from '../../../base/common/uri.js';
import { createDecorator } from '../../instantiation/common/instantiation.js';
import { IWorkspaceFolder } from '../../workspace/common/workspace.js';
export const IConfigurationService = createDecorator<IConfigurationService>('configurationService');
export function isConfigurationOverrides(obj: unknown): obj is IConfigurationOverrides {
return thing
&& (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
configuration.ts ×1
&& (!thing.resource || thing.resource instanceof URI);
export interface IConfigurationOverrides {
overrideIdentifier?: string | null;
resource?: URI | null;
}
export function isConfigurationUpdateOverrides(obj: unknown): obj is IConfigurationUpdateOverrides {
const thing = obj as IConfigurationUpdateOverrides | IConfigurationOverrides;
configurationService.ts ×6
return thing
&& (!(thing as IConfigurationUpdateOverrides).overrideIdentifiers || Array.isArray((thing as IConfigurationUpdateOverrides).overrideIdentifiers))
&& !(thing as IConfigurationOverrides).overrideIdentifier
&& (!thing.resource || thing.resource instanceof URI);
export type IConfigurationUpdateOverrides = Omit<IConfigurationOverrides, 'overrideIdentifier'> & { overrideIdentifiers?: string[] | null };
export const enum ConfigurationTarget {
APPLICATION = 1,
USER,
USER_LOCAL,
USER_REMOTE,
WORKSPACE,
WORKSPACE_FOLDER,
DEFAULT,
MEMORY
}
export function ConfigurationTargetToString(configurationTarget: ConfigurationTarget) {
switch (configurationTarget) {
case ConfigurationTarget.APPLICATION: return 'APPLICATION';
case ConfigurationTarget.USER: return 'USER';
case ConfigurationTarget.USER_LOCAL: return 'USER_LOCAL';
case ConfigurationTarget.USER_REMOTE: return 'USER_REMOTE';
case ConfigurationTarget.WORKSPACE: return 'WORKSPACE';
case ConfigurationTarget.WORKSPACE_FOLDER: return 'WORKSPACE_FOLDER';
case ConfigurationTarget.DEFAULT: return 'DEFAULT';
case ConfigurationTarget.MEMORY: return 'MEMORY';
}
}
export interface IConfigurationChange {
keys: string[];
overrides: [string, string[]][];
}
export interface IConfigurationChangeEvent {
readonly source: ConfigurationTarget;
readonly affectedKeys: ReadonlySet<string>;
readonly change: IConfigurationChange;
affectsConfiguration(configuration: string, overrides?: IConfigurationOverrides): boolean;
}
export interface IInspectValue<T> {
readonly value?: T;
readonly override?: T;
readonly overrides?: { readonly identifiers: string[]; readonly value: T }[];
}
export interface IConfigurationValue<T> {
readonly defaultValue?: T;
readonly applicationValue?: T;
readonly userValue?: T;
readonly userLocalValue?: T;
readonly userRemoteValue?: T;
readonly workspaceValue?: T;
readonly workspaceFolderValue?: T;
readonly memoryValue?: T;
readonly policyValue?: T;
readonly value?: T;
readonly default?: IInspectValue<T>;
readonly application?: IInspectValue<T>;
readonly user?: IInspectValue<T>;
readonly userLocal?: IInspectValue<T>;
readonly userRemote?: IInspectValue<T>;
readonly workspace?: IInspectValue<T>;
readonly workspaceFolder?: IInspectValue<T>;
readonly memory?: IInspectValue<T>;
readonly policy?: { value?: T };
readonly overrideIdentifiers?: string[];
}
export function getConfigValueInTarget<T>(configValue: IConfigurationValue<T>, scope: ConfigurationTarget): T | undefined {
switch (scope) {
case ConfigurationTarget.APPLICATION:
return configValue.applicationValue;
case ConfigurationTarget.USER:
return configValue.userValue;
case ConfigurationTarget.USER_LOCAL:
return configValue.userLocalValue;
case ConfigurationTarget.USER_REMOTE:
return configValue.userRemoteValue;
case ConfigurationTarget.WORKSPACE:
return configValue.workspaceValue;
case ConfigurationTarget.WORKSPACE_FOLDER:
return configValue.workspaceFolderValue;
case ConfigurationTarget.DEFAULT:
return configValue.defaultValue;
case ConfigurationTarget.MEMORY:
return configValue.memoryValue;
default:
assertNever(scope);
}
}
export function isConfigured<T>(configValue: IConfigurationValue<T>): configValue is IConfigurationValue<T> & { value: T } {
configValue.userValue !== undefined ||
configValue.userLocalValue !== undefined ||
configValue.userRemoteValue !== undefined ||
configValue.workspaceValue !== undefined ||
configValue.workspaceFolderValue !== undefined;
}
export interface IConfigurationUpdateOptions {
/**
* If `true`, do not notifies the error to user by showing the message box. Default is `false`.
*/
donotNotifyError?: boolean;
/**
* How to handle dirty file when updating the configuration.
*/
handleDirtyFile?: 'save' | 'revert';
}
export interface IConfigurationService {
readonly _serviceBrand: undefined;
readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent>;
getConfigurationData(): IConfigurationData | null;
/**
* Fetches the value of the section for the given overrides.
* Value can be of native type or an object keyed off the section name.
*
* @param section - Section of the configuration. Can be `null` or `undefined`.
* @param overrides - Overrides that has to be applied while fetching
*
*/
getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
/**
* Update a configuration value.
*
* Use `target` to update the configuration in a specific `ConfigurationTarget`.
*
* Use `overrides` to update the configuration for a resource or for override identifiers or both.
*
* Passing a resource through overrides will update the configuration in the workspace folder containing that resource.
*
* *Note 1:* Updating configuration to a default value will remove the configuration from the requested target. If not target is passed, it will be removed from all writeable targets.
*
* *Note 2:* Use `undefined` value to remove the configuration from the given target. If not target is passed, it will be removed from all writeable targets.
*
* Use `donotNotifyError` and set it to `true` to surpresss errors.
*
* @param key setting to be updated
* @param value The new value
*/
updateValue(key: string, value: unknown): Promise<void>;
updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise<void>;
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
inspect<T>(key: string, overrides?: IConfigurationOverrides): IConfigurationValue<Readonly<T>>;
reloadConfiguration(target?: ConfigurationTarget | IWorkspaceFolder): Promise<void>;
keys(): {
default: string[];
policy: string[];
user: string[];
workspace: string[];
workspaceFolder: string[];
memory?: string[];
};
}
export interface IConfigurationModel {
contents: IStringDictionary<unknown>;
keys: string[];
overrides: IOverrides[];
raw?: ReadonlyArray<IStringDictionary<unknown>> | IStringDictionary<unknown>;
}
export interface IOverrides {
keys: string[];
contents: IStringDictionary<unknown>;
identifiers: string[];
}
export interface IConfigurationData {
defaults: IConfigurationModel;
policy: IConfigurationModel;
application: IConfigurationModel;
userLocal: IConfigurationModel;
userRemote: IConfigurationModel;
workspace: IConfigurationModel;
folders: [UriComponents, IConfigurationModel][];
}
export interface IConfigurationCompareResult {
added: string[];
removed: string[];
updated: string[];
overrides: [string, string[]][];
}
export function toValuesTree(properties: IStringDictionary<unknown>, conflictReporter: (message: string) => void): IStringDictionary<unknown> {
for (const key in properties) {
}
return root;
}
export function addToValueTree(settingsTreeRoot: IStringDictionary<unknown>, key: string, value: unknown, conflictReporter: (message: string) => void): void {
const last = segments.pop()!;
let curr: IStringDictionary<unknown> = settingsTreeRoot;
for (let i = 0; i < segments.length; i++) {
let obj = curr[s];
switch (typeof obj) {
case 'undefined':
break;
conflictReporter(`Ignoring ${key} as ${segments.slice(0, i + 1).join('.')} is null`);
configuration.ts ×1
return;
}
conflictReporter(`Ignoring ${key} as ${segments.slice(0, i + 1).join('.')} is ${JSON.stringify(obj)}`);
return;
}
if (typeof curr === 'object' && curr !== null) {
try {
(curr as IStringDictionary<unknown>)[last] = value; // workaround https://github.com/microsoft/vscode/issues/13606
} catch (e) {
conflictReporter(`Ignoring ${key} as ${segments.join('.')} is ${JSON.stringify(curr)}`);
}
conflictReporter(`Ignoring ${key} as ${segments.join('.')} is ${JSON.stringify(curr)}`);
}
export function removeFromValueTree(valueTree: IStringDictionary<unknown>, key: string): void {
doRemoveFromValueTree(valueTree, segments);
}
function doRemoveFromValueTree(valueTree: IStringDictionary<unknown> | unknown, segments: string[]): void {
configuration.ts ×4
if (!valueTree) {
return;
}
const valueTreeRecord = valueTree as IStringDictionary<unknown>;
const first = segments.shift()!;
if (segments.length === 0) {
delete valueTreeRecord[first];
return;
}
if (Object.keys(valueTreeRecord).indexOf(first) !== -1) {
const value = valueTreeRecord[first];
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
if (Object.keys(value as object).length === 0) {
}
/**
* A helper function to get the configuration value with a specific settings path (e.g. config.some.setting)
*/
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string): T | undefined;
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string, defaultValue: T): T;
export function getConfigurationValue<T>(config: IStringDictionary<unknown>, settingPath: string, defaultValue?: T): T | undefined {
function accessSetting(config: IStringDictionary<unknown>, path: string[]): unknown {
configuration.ts ×3
let current: unknown = config;
for (const component of path) {
if (typeof current !== 'object' || current === null) {
}
}
const path = settingPath.split('.');
const result = accessSetting(config, path);
return typeof result === 'undefined' ? defaultValue : result as T;
}
export function merge(base: IStringDictionary<unknown>, add: IStringDictionary<unknown>, overwrite: boolean): void {
if (key !== '__proto__') {
if (key in base) {
if (types.isObject(base[key]) && types.isObject(add[key])) {
merge(base[key] as IStringDictionary<unknown>, add[key] as IStringDictionary<unknown>, overwrite);
configuration.ts ×1
base[key] = add[key];
}
} else {
}
});
}
export function getLanguageTagSettingPlainKey(settingKey: string) {
.replace(/^\[/, '')
.replace(/]$/g, '')
.replace(/\]\[/g, ', ');
}