configurationService.ts ×18

Frontier kind: Code frontier

unlabeled · c_eb9a06b1f8b2

1058 tests · 12814 LOC · 55 files · introduces 0 tests · 89 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges89 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1822 ranges12814 lines · 55 files · Browse complete extent
All tests (intent)
1058 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 89 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/configuration/common/configurationService.ts 89 introduced LOC · 18 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- configurationService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { distinct, equals as arrayEquals } from '../../../base/common/arrays.js';
7 > import { Queue, RunOnceScheduler } from '../../../base/common/async.js';
8 > import { VSBuffer } from '../../../base/common/buffer.js';
9 > import { Emitter, Event } from '../../../base/common/event.js';
10 > import { JSONPath, ParseError, parse } from '../../../base/common/json.js';
11 > import { applyEdits, setProperty } from '../../../base/common/jsonEdit.js';
12 > import { Edit, FormattingOptions } from '../../../base/common/jsonFormatter.js';
13 > import { Disposable, IDisposable } from '../../../base/common/lifecycle.js';
14 > import { ResourceMap } from '../../../base/common/map.js';
15 > import { equals } from '../../../base/common/objects.js';
16 > import { OS, OperatingSystem } from '../../../base/common/platform.js';
17 > import { extUriBiasedIgnorePathCase } from '../../../base/common/resources.js';
18 > import { URI } from '../../../base/common/uri.js';
19 > import { ConfigurationTarget, IConfigurationChange, IConfigurationChangeEvent, IConfigurationData, IConfigurationOverrides, IConfigurationService, IConfigurationUpdateOptions, IConfigurationUpdateOverrides, IConfigurationValue, isConfigurationOverrides, isConfigurationUpdateOverrides } from './configuration.js';
20 > import { Configuration, ConfigurationChangeEvent, ConfigurationModel, UserSettings } from './configurationModels.js';
21 > import { keyFromOverrideIdentifiers } from './configurationRegistry.js';
22 > import { DefaultConfiguration, IPolicyConfiguration, NullPolicyConfiguration, PolicyConfiguration } from './configurations.js';
23 > import { FileOperationError, FileOperationResult, IFileService } from '../../files/common/files.js';
24 > import { ILogService } from '../../log/common/log.js';
25 > import { IPolicyService, NullPolicyService } from '../../policy/common/policy.js';
26 >
27 > export class ConfigurationService extends Disposable implements IConfigurationService, IDisposable {
28 >
29 > declare readonly _serviceBrand: undefined;
30 >
31 > private configuration: Configuration;
32 > private readonly defaultConfiguration: DefaultConfiguration;
33 > private readonly policyConfiguration: IPolicyConfiguration;
34 > private readonly userConfiguration: UserSettings;
35 > private readonly reloadConfigurationScheduler: RunOnceScheduler;
36 >
37 > private readonly _onDidChangeConfiguration: Emitter<IConfigurationChangeEvent> = this._register(new Emitter<IConfigurationChangeEvent>());
38 > readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
39 >
40 > private readonly configurationEditing: ConfigurationEditing;
41 >
42 > constructor(
43 private readonly settingsResource: URI,
44 fileService: IFileService,
69 this._register(this.userConfiguration.onDidChange(() => this.reloadConfigurationScheduler.schedule()));
70 }
72 > async initialize(): Promise<void> {
73 const [defaultModel, policyModel, userModel] = await Promise.all([this.defaultConfiguration.initialize(), this.policyConfiguration.initialize(), this.userConfiguration.loadConfiguration()]);
74 this.configuration = new Configuration(
85 );
86 }
88 > getConfigurationData(): IConfigurationData {
89 return this.configuration.toData();
90 }
92 > getValue<T>(): T;
93 > getValue<T>(section: string): T;
94 > getValue<T>(overrides: IConfigurationOverrides): T;
95 > getValue<T>(section: string, overrides: IConfigurationOverrides): T;
96 > getValue(arg1?: unknown, arg2?: unknown): unknown {
97 const section = typeof arg1 === 'string' ? arg1 : undefined;
98 const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
99 return this.configuration.getValue(section, overrides, undefined);
100 }
102 > updateValue(key: string, value: unknown): Promise<void>;
103 > updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides): Promise<void>;
104 > updateValue(key: string, value: unknown, target: ConfigurationTarget): Promise<void>;
105 > updateValue(key: string, value: unknown, overrides: IConfigurationOverrides | IConfigurationUpdateOverrides, target: ConfigurationTarget, options?: IConfigurationUpdateOptions): Promise<void>;
106 > async updateValue(key: string, value: unknown, arg3?: unknown, arg4?: unknown, options?: IConfigurationUpdateOptions): Promise<void> {
107 const overrides: IConfigurationUpdateOverrides | undefined = isConfigurationUpdateOverrides(arg3) ? arg3
108 : isConfigurationOverrides(arg3) ? { resource: arg3.resource, overrideIdentifiers: arg3.overrideIdentifier ? [arg3.overrideIdentifier] : undefined } : undefined;
143 await this.reloadConfiguration();
144 }
146 > inspect<T>(key: string, overrides: IConfigurationOverrides = {}): IConfigurationValue<T> {
147 return this.configuration.inspect<T>(key, overrides, undefined);
148 }
150 > keys(): {
151 default: string[];
152 policy: string[];
157 return this.configuration.keys(undefined);
158 }
160 > async reloadConfiguration(): Promise<void> {
161 const configurationModel = await this.userConfiguration.loadConfiguration();
162 this.onDidChangeUserConfiguration(configurationModel);
163 }
165 > private onDidChangeUserConfiguration(userConfigurationModel: ConfigurationModel): void {
166 const previous = this.configuration.toData();
167 const change = this.configuration.compareAndUpdateLocalUserConfiguration(userConfigurationModel);
168 this.trigger(change, previous, ConfigurationTarget.USER);
169 }
171 > private onDidDefaultConfigurationChange(defaultConfigurationModel: ConfigurationModel, properties: string[]): void {
172 const previous = this.configuration.toData();
173 const change = this.configuration.compareAndUpdateDefaultConfiguration(defaultConfigurationModel, properties);
174 this.trigger(change, previous, ConfigurationTarget.DEFAULT);
175 }
177 > private onDidPolicyConfigurationChange(policyConfiguration: ConfigurationModel): void {
178 const previous = this.configuration.toData();
179 const change = this.configuration.compareAndUpdatePolicyConfiguration(policyConfiguration);
180 this.trigger(change, previous, ConfigurationTarget.DEFAULT);
181 }
183 > private trigger(configurationChange: IConfigurationChange, previous: IConfigurationData, source: ConfigurationTarget): void {
184 const event = new ConfigurationChangeEvent(configurationChange, { data: previous }, this.configuration, undefined, this.logService);
185 event.source = source;
186 this._onDidChangeConfiguration.fire(event);
187 }
189 >
190 > class ConfigurationEditing {
191 >
192 > private readonly queue: Queue<void>;
193 >
194 > constructor(
195 private readonly settingsResource: URI,
196 private readonly fileService: IFileService,
199 this.queue = new Queue<void>();
200 }
202 > write(path: JSONPath, value: unknown): Promise<void> {
203 return this.queue.queue(() => this.doWriteConfiguration(path, value)); // queue up writes to prevent race conditions
204 }
206 > private async doWriteConfiguration(path: JSONPath, value: unknown): Promise<void> {
207 let content: string;
208 try {
228 await this.fileService.writeFile(this.settingsResource, VSBuffer.fromString(content));
229 }
231 > private getEdits(content: string, path: JSONPath, value: unknown): Edit[] {
232 const { tabSize, insertSpaces, eol } = this.formattingOptions;
233
244 return setProperty(content, path, value, { tabSize, insertSpaces, eol });
245 }
247 > private _formattingOptions: Required<FormattingOptions> | undefined;
248 > private get formattingOptions(): Required<FormattingOptions> {
249 if (!this._formattingOptions) {
250 let eol = OS === OperatingSystem.Linux || OS === OperatingSystem.Macintosh ? '\n' : '\r\n';