src/vs/workbench/services/configuration/common/configurationModels.ts
174 LOC · 122 covered · 52 uncovered · 30 ranges · 8 concepts · 4 introducers · 7 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.
/*---------------------------------------------------------------------------------------------
configurationModels.ts ×19
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { equals } from '../../../../base/common/objects.js';
import { toValuesTree, IConfigurationModel, IConfigurationOverrides, IConfigurationValue, IConfigurationChange } from '../../../../platform/configuration/common/configuration.js';
import { Configuration as BaseConfiguration, ConfigurationModelParser, ConfigurationModel, ConfigurationParseOptions } from '../../../../platform/configuration/common/configurationModels.js';
import { IStoredWorkspaceFolder } from '../../../../platform/workspaces/common/workspaces.js';
import { Workspace } from '../../../../platform/workspace/common/workspace.js';
import { ResourceMap } from '../../../../base/common/map.js';
import { URI } from '../../../../base/common/uri.js';
import { isBoolean } from '../../../../base/common/types.js';
import { distinct } from '../../../../base/common/arrays.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { IStringDictionary } from '../../../../base/common/collections.js';
export class WorkspaceConfigurationModelParser extends ConfigurationModelParser {
private _folders: IStoredWorkspaceFolder[] = [];
private _transient: boolean = false;
private _settingsModelParser: ConfigurationModelParser;
private _launchModel: ConfigurationModel;
private _tasksModel: ConfigurationModel;
constructor(name: string, logService: ILogService) {
super(name, logService);
this._settingsModelParser = new ConfigurationModelParser(name, logService);
this._launchModel = ConfigurationModel.createEmptyModel(logService);
this._tasksModel = ConfigurationModel.createEmptyModel(logService);
}
get folders(): IStoredWorkspaceFolder[] {
return this._folders;
}
get transient(): boolean {
return this._transient;
}
get settingsModel(): ConfigurationModel {
return this._settingsModelParser.configurationModel;
}
get launchModel(): ConfigurationModel {
return this._launchModel;
}
get tasksModel(): ConfigurationModel {
return this._tasksModel;
}
reparseWorkspaceSettings(configurationParseOptions: ConfigurationParseOptions): void {
this._settingsModelParser.reparse(configurationParseOptions);
}
getRestrictedWorkspaceSettings(): string[] {
return this._settingsModelParser.restrictedConfigurations;
}
protected override doParseRaw(raw: IStringDictionary<unknown>, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel {
this._folders = (raw['folders'] || []) as IStoredWorkspaceFolder[];
this._transient = isBoolean(raw['transient']) && raw['transient'];
this._settingsModelParser.parseRaw(raw['settings'] as IStringDictionary<unknown>, configurationParseOptions);
this._launchModel = this.createConfigurationModelFrom(raw, 'launch');
this._tasksModel = this.createConfigurationModelFrom(raw, 'tasks');
return super.doParseRaw(raw, configurationParseOptions);
}
private createConfigurationModelFrom(raw: IStringDictionary<unknown>, key: string): ConfigurationModel {
const data = raw[key] as IStringDictionary<unknown> | undefined;
if (data) {
const contents = toValuesTree(data, message => console.error(`Conflict in settings file ${this._name}: ${message}`));
const scopedContents = Object.create(null);
scopedContents[key] = contents;
const keys = Object.keys(data).map(k => `${key}.${k}`);
return new ConfigurationModel(scopedContents, keys, [], undefined, this.logService);
}
return ConfigurationModel.createEmptyModel(this.logService);
}
export class StandaloneConfigurationModelParser extends ConfigurationModelParser {
constructor(name: string, private readonly scope: string, logService: ILogService,) {
}
protected override doParseRaw(raw: IStringDictionary<unknown>, configurationParseOptions?: ConfigurationParseOptions): IConfigurationModel {
const contents = toValuesTree(raw, message => console.error(`Conflict in settings file ${this._name}: ${message}`));
configurationModels.ts ×2
const scopedContents = Object.create(null);
scopedContents[this.scope] = contents;
const keys = Object.keys(raw).map(key => `${this.scope}.${key}`);
return { contents: scopedContents, keys, overrides: [] };
}
}
export class Configuration extends BaseConfiguration {
constructor(
policy: ConfigurationModel,
application: ConfigurationModel,
localUser: ConfigurationModel,
remoteUser: ConfigurationModel,
workspaceConfiguration: ConfigurationModel,
folders: ResourceMap<ConfigurationModel>,
memoryConfiguration: ConfigurationModel,
memoryConfigurationByResource: ResourceMap<ConfigurationModel>,
private readonly _workspace: Workspace | undefined,
logService: ILogService
) {
super(defaults, policy, application, localUser, remoteUser, workspaceConfiguration, folders, memoryConfiguration, memoryConfigurationByResource, logService);
}
override getValue(key: string | undefined, overrides: IConfigurationOverrides = {}): unknown {
}
override inspect<C>(key: string, overrides: IConfigurationOverrides = {}): IConfigurationValue<C> {
return super.inspect(key, overrides, this._workspace);
}
override keys(): {
default: string[];
policy: string[];
user: string[];
workspace: string[];
workspaceFolder: string[];
} {
return super.keys(this._workspace);
}
override compareAndDeleteFolderConfiguration(folder: URI): IConfigurationChange {
if (this._workspace && this._workspace.folders.length > 0 && this._workspace.folders[0].uri.toString() === folder.toString()) {
// Do not remove workspace configuration
return { keys: [], overrides: [] };
}
return super.compareAndDeleteFolderConfiguration(folder);
}
compare(other: Configuration): IConfigurationChange {
const compare = (fromKeys: string[], toKeys: string[], overrideIdentifier?: string): string[] => {
configurationModels.ts ×6
const keys: string[] = [];
keys.push(...toKeys.filter(key => fromKeys.indexOf(key) === -1));
keys.push(...fromKeys.filter(key => toKeys.indexOf(key) === -1));
keys.push(...fromKeys.filter(key => {
// Ignore if the key does not exist in both models
if (toKeys.indexOf(key) === -1) {
}
if (!equals(this.getValue(key, { overrideIdentifier }), other.getValue(key, { overrideIdentifier }))) {
}
return this._workspace && this._workspace.folders.some(folder => !equals(this.getValue(key, { resource: folder.uri, overrideIdentifier }), other.getValue(key, { resource: folder.uri, overrideIdentifier })));
}));
return keys;
};
const keys = compare(this.allKeys(), other.allKeys());
const overrides: [string, string[]][] = [];
const allOverrideIdentifiers = distinct([...this.allOverrideIdentifiers(), ...other.allOverrideIdentifiers()]);
for (const overrideIdentifier of allOverrideIdentifiers) {
const keys = compare(this.getAllKeysForOverrideIdentifier(overrideIdentifier), other.getAllKeysForOverrideIdentifier(overrideIdentifier), overrideIdentifier);
if (keys.length) {
}
return { keys, overrides };
}
}