@codingame/monaco-vscode-configuration-service-override 37.1.0 → 37.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common.d.ts +23 -0
- package/common.js +61 -0
- package/index.d.ts +3 -21
- package/index.js +21 -63
- package/package.json +11 -3
- package/session.d.ts +3 -0
- package/session.js +66 -0
- package/vscode/src/vs/sessions/contrib/configuration/browser/configuration.contribution.d.ts +1 -0
- package/vscode/src/vs/sessions/contrib/configuration/browser/configuration.contribution.js +13 -0
- package/vscode/src/vs/sessions/services/configuration/browser/configurationService.d.ts +73 -0
- package/vscode/src/vs/sessions/services/configuration/browser/configurationService.js +499 -0
- package/vscode/src/vs/sessions/services/workspace/browser/workspaceContextService.d.ts +39 -0
- package/vscode/src/vs/sessions/services/workspace/browser/workspaceContextService.js +152 -0
- package/vscode/src/vs/workbench/api/common/configurationExtensionPoint.js +68 -68
- package/vscode/src/vs/workbench/contrib/workspaces/browser/workspaces.contribution.js +9 -9
- package/vscode/src/vs/workbench/services/configuration/browser/configuration.js +17 -12
- package/vscode/src/vs/workbench/services/configuration/browser/configurationService.js +9 -9
- package/vscode/src/vs/workbench/services/configuration/common/configurationEditing.js +43 -43
- package/vscode/src/vs/workbench/services/configuration/common/configurationModels.js +2 -2
- package/vscode/src/vs/workbench/services/configurationResolver/browser/baseConfigurationResolverService.js +8 -8
- package/vscode/src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.js +11 -11
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
|
|
2
|
+
import { onUnexpectedError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
|
|
3
|
+
import { Emitter, Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
4
|
+
import { Disposable, DisposableMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import { ResourceMap } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
|
|
6
|
+
import { Promises, Queue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
7
|
+
import { VSBuffer } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
|
|
8
|
+
import { parse } from '@codingame/monaco-vscode-api/vscode/vs/base/common/json';
|
|
9
|
+
import { applyEdits, setProperty } from '@codingame/monaco-vscode-api/vscode/vs/base/common/jsonEdit';
|
|
10
|
+
import { deepClone, equals } from '@codingame/monaco-vscode-api/vscode/vs/base/common/objects';
|
|
11
|
+
import { distinct, equals as equals$1 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
|
|
12
|
+
import { OS, OperatingSystem } from '@codingame/monaco-vscode-api/vscode/vs/base/common/platform';
|
|
13
|
+
import { isConfigurationOverrides, isConfigurationUpdateOverrides, ConfigurationTarget } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration';
|
|
14
|
+
import { ChatAIDisabledSettingId } from '@codingame/monaco-vscode-api/vscode/vs/platform/chat/common/chatSettings';
|
|
15
|
+
import { ConfigurationModel, ConfigurationChangeEvent } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configurationModels';
|
|
16
|
+
import { NullPolicyConfiguration, PolicyConfiguration } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configurations';
|
|
17
|
+
import { Extensions, keyFromOverrideIdentifiers } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configurationRegistry';
|
|
18
|
+
import { FileOperationResult } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files';
|
|
19
|
+
import { NullPolicyService } from '@codingame/monaco-vscode-api/vscode/vs/platform/policy/common/policy';
|
|
20
|
+
import { Registry } from '@codingame/monaco-vscode-api/vscode/vs/platform/registry/common/platform';
|
|
21
|
+
import { WorkbenchState } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace';
|
|
22
|
+
import { DefaultConfiguration, UserConfiguration, WorkspaceConfiguration, FolderConfiguration } from '../../../../workbench/services/configuration/browser/configuration.js';
|
|
23
|
+
import { FOLDER_SETTINGS_PATH, APPLICATION_SCOPES, APPLY_ALL_PROFILES_SETTING, FOLDER_CONFIG_FOLDER_NAME } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/configuration/common/configuration';
|
|
24
|
+
import { Configuration } from '../../../../workbench/services/configuration/common/configurationModels.js';
|
|
25
|
+
import '../../../../workbench/services/configuration/browser/configurationService.js';
|
|
26
|
+
|
|
27
|
+
class SessionsDefaultConfiguration extends DefaultConfiguration {
|
|
28
|
+
getDefaultValue(_key, propertySchema) {
|
|
29
|
+
if (propertySchema.agentsWindow && propertySchema.defaultValueSource !== "experiments") {
|
|
30
|
+
return deepClone(propertySchema.agentsWindow.default);
|
|
31
|
+
}
|
|
32
|
+
return super.getDefaultValue(_key, propertySchema);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class ConfigurationService extends Disposable {
|
|
36
|
+
constructor(
|
|
37
|
+
userDataProfileService,
|
|
38
|
+
workspaceService,
|
|
39
|
+
uriIdentityService,
|
|
40
|
+
fileService,
|
|
41
|
+
policyService,
|
|
42
|
+
logService,
|
|
43
|
+
configurationCache,
|
|
44
|
+
environmentService
|
|
45
|
+
) {
|
|
46
|
+
super();
|
|
47
|
+
this.workspaceService = workspaceService;
|
|
48
|
+
this.uriIdentityService = uriIdentityService;
|
|
49
|
+
this.fileService = fileService;
|
|
50
|
+
this.logService = logService;
|
|
51
|
+
this.cachedFolderConfigs = this._register(( new DisposableMap(( new ResourceMap()))));
|
|
52
|
+
this.agentsWindowReadOnlyKeys = ( new Set());
|
|
53
|
+
this._onDidChangeConfiguration = this._register(( new Emitter()));
|
|
54
|
+
this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
|
|
55
|
+
this.onDidChangeRestrictedSettings = Event.None;
|
|
56
|
+
this.restrictedSettings = {
|
|
57
|
+
default: []
|
|
58
|
+
};
|
|
59
|
+
this.configurationRegistry = ( Registry.as(Extensions.Configuration));
|
|
60
|
+
this.settingsResource = userDataProfileService.currentProfile.settingsResource;
|
|
61
|
+
this.defaultConfiguration = this._register(( new SessionsDefaultConfiguration(
|
|
62
|
+
userDataProfileService.currentProfile.id,
|
|
63
|
+
configurationCache,
|
|
64
|
+
environmentService,
|
|
65
|
+
logService
|
|
66
|
+
)));
|
|
67
|
+
this.policyConfiguration = policyService instanceof NullPolicyService ? ( new NullPolicyConfiguration()) : this._register(( new PolicyConfiguration(this.defaultConfiguration, policyService, logService)));
|
|
68
|
+
this.initAgentsWindowReadOnlyKeys();
|
|
69
|
+
this.userConfiguration = this._register(( new UserConfiguration(
|
|
70
|
+
userDataProfileService.currentProfile.settingsResource,
|
|
71
|
+
userDataProfileService.currentProfile.tasksResource,
|
|
72
|
+
userDataProfileService.currentProfile.mcpResource,
|
|
73
|
+
{
|
|
74
|
+
exclude: [...this.agentsWindowReadOnlyKeys]
|
|
75
|
+
},
|
|
76
|
+
fileService,
|
|
77
|
+
uriIdentityService,
|
|
78
|
+
logService
|
|
79
|
+
)));
|
|
80
|
+
this.workspaceConfiguration = this._register(( new WorkspaceConfiguration({
|
|
81
|
+
needsCaching: () => false,
|
|
82
|
+
read: async () => "",
|
|
83
|
+
write: async () => {},
|
|
84
|
+
remove: async () => {}
|
|
85
|
+
}, fileService, uriIdentityService, logService)));
|
|
86
|
+
this.configurationEditing = ( new ConfigurationEditing(fileService, this));
|
|
87
|
+
this._configuration = ( new Configuration(
|
|
88
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
89
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
90
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
91
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
92
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
93
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
94
|
+
( new ResourceMap()),
|
|
95
|
+
ConfigurationModel.createEmptyModel(logService),
|
|
96
|
+
( new ResourceMap()),
|
|
97
|
+
this.workspaceService.getWorkspace(),
|
|
98
|
+
this.logService
|
|
99
|
+
));
|
|
100
|
+
this._register(this.defaultConfiguration.onDidChangeConfiguration((
|
|
101
|
+
{
|
|
102
|
+
defaults,
|
|
103
|
+
properties
|
|
104
|
+
}
|
|
105
|
+
) => this.onDefaultConfigurationChanged(defaults, properties)));
|
|
106
|
+
this._register(this.policyConfiguration.onDidChangeConfiguration(
|
|
107
|
+
configurationModel => this.onPolicyConfigurationChanged(configurationModel)
|
|
108
|
+
));
|
|
109
|
+
this._register(
|
|
110
|
+
this.userConfiguration.onDidChangeConfiguration(userConfiguration => this.onUserConfigurationChanged(userConfiguration))
|
|
111
|
+
);
|
|
112
|
+
this._register(
|
|
113
|
+
this.workspaceConfiguration.onDidUpdateConfiguration(() => this.onWorkspaceConfigurationChanged())
|
|
114
|
+
);
|
|
115
|
+
this._register(
|
|
116
|
+
this.workspaceService.onWillChangeWorkspaceFolders(e => e.join(this.loadFolderConfigurations(e.changes.added)))
|
|
117
|
+
);
|
|
118
|
+
this._register(
|
|
119
|
+
this.workspaceService.onDidChangeWorkspaceFolders(e => this.onWorkspaceFoldersChanged(e))
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
async initialize() {
|
|
123
|
+
const workspace = this.workspaceService.getWorkspace();
|
|
124
|
+
const workspaceIdentifier = {
|
|
125
|
+
id: workspace.id,
|
|
126
|
+
configPath: workspace.configuration
|
|
127
|
+
};
|
|
128
|
+
const [defaultModel, policyModel, userModel] = await Promise.all([
|
|
129
|
+
this.defaultConfiguration.initialize(),
|
|
130
|
+
this.policyConfiguration.initialize(),
|
|
131
|
+
this.userConfiguration.initialize(),
|
|
132
|
+
this.workspaceConfiguration.initialize(workspaceIdentifier, true)
|
|
133
|
+
]);
|
|
134
|
+
this.workspaceConfiguration.reparseWorkspaceSettings({
|
|
135
|
+
exclude: [...this.agentsWindowReadOnlyKeys]
|
|
136
|
+
});
|
|
137
|
+
this._configuration = ( new Configuration(
|
|
138
|
+
defaultModel,
|
|
139
|
+
policyModel,
|
|
140
|
+
ConfigurationModel.createEmptyModel(this.logService),
|
|
141
|
+
userModel,
|
|
142
|
+
ConfigurationModel.createEmptyModel(this.logService),
|
|
143
|
+
this.workspaceConfiguration.getConfiguration(),
|
|
144
|
+
( new ResourceMap()),
|
|
145
|
+
ConfigurationModel.createEmptyModel(this.logService),
|
|
146
|
+
( new ResourceMap()),
|
|
147
|
+
workspace,
|
|
148
|
+
this.logService
|
|
149
|
+
));
|
|
150
|
+
await this.loadFolderConfigurations(workspace.folders);
|
|
151
|
+
}
|
|
152
|
+
getConfigurationData() {
|
|
153
|
+
return this._configuration.toData();
|
|
154
|
+
}
|
|
155
|
+
getValue(arg1, arg2) {
|
|
156
|
+
const section = typeof arg1 === "string" ? arg1 : undefined;
|
|
157
|
+
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : undefined;
|
|
158
|
+
return this._configuration.getValue(section, overrides);
|
|
159
|
+
}
|
|
160
|
+
async updateValue(key, value, arg3, arg4, _options) {
|
|
161
|
+
const overrides = isConfigurationUpdateOverrides(arg3) ? arg3 : isConfigurationOverrides(arg3) ? {
|
|
162
|
+
resource: arg3.resource,
|
|
163
|
+
overrideIdentifiers: arg3.overrideIdentifier ? [arg3.overrideIdentifier] : undefined
|
|
164
|
+
} : undefined;
|
|
165
|
+
let target = (overrides ? arg4 : arg3);
|
|
166
|
+
if (key === ChatAIDisabledSettingId) {
|
|
167
|
+
target = ConfigurationTarget.WORKSPACE;
|
|
168
|
+
}
|
|
169
|
+
const targets = target ? [target] : [];
|
|
170
|
+
if (overrides?.overrideIdentifiers) {
|
|
171
|
+
overrides.overrideIdentifiers = distinct(overrides.overrideIdentifiers);
|
|
172
|
+
overrides.overrideIdentifiers = overrides.overrideIdentifiers.length ? overrides.overrideIdentifiers : undefined;
|
|
173
|
+
}
|
|
174
|
+
const inspect = this.inspect(key, {
|
|
175
|
+
resource: overrides?.resource,
|
|
176
|
+
overrideIdentifier: overrides?.overrideIdentifiers ? overrides.overrideIdentifiers[0] : undefined
|
|
177
|
+
});
|
|
178
|
+
if (inspect.policyValue !== undefined) {
|
|
179
|
+
throw ( new Error(`Unable to write ${key} because it is configured in system policy.`));
|
|
180
|
+
}
|
|
181
|
+
if (( this.agentsWindowReadOnlyKeys.has(key))) {
|
|
182
|
+
throw ( new Error(`Unable to write ${key} because it is read-only in the Agents window.`));
|
|
183
|
+
}
|
|
184
|
+
if (!targets.length) {
|
|
185
|
+
targets.push(...this.deriveConfigurationTargets(key, value, inspect));
|
|
186
|
+
if (equals(value, inspect.defaultValue) && targets.length === 1 && targets[0] === ConfigurationTarget.USER) {
|
|
187
|
+
value = undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (overrides?.overrideIdentifiers?.length && overrides.overrideIdentifiers.length > 1) {
|
|
191
|
+
const overrideIdentifiers = overrides.overrideIdentifiers.sort();
|
|
192
|
+
const existingOverrides = this._configuration.localUserConfiguration.overrides.find(
|
|
193
|
+
override => equals$1([...override.identifiers].sort(), overrideIdentifiers)
|
|
194
|
+
);
|
|
195
|
+
if (existingOverrides) {
|
|
196
|
+
overrides.overrideIdentifiers = existingOverrides.identifiers;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
await Promises.settled(targets.map(t => this.writeConfigurationValue(key, value, t, overrides)));
|
|
200
|
+
}
|
|
201
|
+
async writeConfigurationValue(key, value, target, overrides) {
|
|
202
|
+
let path = overrides?.overrideIdentifiers?.length ? [keyFromOverrideIdentifiers(overrides.overrideIdentifiers), key] : [key];
|
|
203
|
+
const settingsResource = this.getSettingsResource(target, overrides?.resource ?? undefined);
|
|
204
|
+
if (this.isWorkspaceConfigurationResource(settingsResource)) {
|
|
205
|
+
path = ["settings", ...path];
|
|
206
|
+
}
|
|
207
|
+
await this.configurationEditing.write(settingsResource, path, value);
|
|
208
|
+
await this.reloadConfiguration();
|
|
209
|
+
}
|
|
210
|
+
deriveConfigurationTargets(_key, value, inspect) {
|
|
211
|
+
if (equals(value, inspect.value)) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
const definedTargets = [];
|
|
215
|
+
if (inspect.workspaceFolderValue !== undefined) {
|
|
216
|
+
definedTargets.push(ConfigurationTarget.WORKSPACE_FOLDER);
|
|
217
|
+
}
|
|
218
|
+
if (inspect.workspaceValue !== undefined) {
|
|
219
|
+
definedTargets.push(ConfigurationTarget.WORKSPACE);
|
|
220
|
+
}
|
|
221
|
+
if (inspect.userValue !== undefined) {
|
|
222
|
+
definedTargets.push(ConfigurationTarget.USER);
|
|
223
|
+
}
|
|
224
|
+
if (value === undefined) {
|
|
225
|
+
return definedTargets;
|
|
226
|
+
}
|
|
227
|
+
return [definedTargets[0] || ConfigurationTarget.USER];
|
|
228
|
+
}
|
|
229
|
+
isWorkspaceConfigurationResource(resource) {
|
|
230
|
+
const workspace = this.workspaceService.getWorkspace();
|
|
231
|
+
return !!(workspace.configuration && this.uriIdentityService.extUri.isEqual(workspace.configuration, resource));
|
|
232
|
+
}
|
|
233
|
+
getSettingsResource(target, resource) {
|
|
234
|
+
if (target === ConfigurationTarget.WORKSPACE_FOLDER) {
|
|
235
|
+
if (resource) {
|
|
236
|
+
const folder = this.workspaceService.getWorkspaceFolder(resource);
|
|
237
|
+
if (folder) {
|
|
238
|
+
return this.uriIdentityService.extUri.joinPath(folder.uri, FOLDER_SETTINGS_PATH);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (target === ConfigurationTarget.WORKSPACE) {
|
|
243
|
+
const workspace = this.workspaceService.getWorkspace();
|
|
244
|
+
if (workspace.configuration) {
|
|
245
|
+
return workspace.configuration;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return this.settingsResource;
|
|
249
|
+
}
|
|
250
|
+
inspect(key, overrides) {
|
|
251
|
+
return this._configuration.inspect(key, overrides);
|
|
252
|
+
}
|
|
253
|
+
keys() {
|
|
254
|
+
return ( this._configuration.keys());
|
|
255
|
+
}
|
|
256
|
+
async reloadConfiguration(_target) {
|
|
257
|
+
this.reloadDefaultConfiguration();
|
|
258
|
+
if (_target === ConfigurationTarget.DEFAULT) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const userModel = await this.userConfiguration.initialize();
|
|
262
|
+
const previousData = this._configuration.toData();
|
|
263
|
+
const change = this._configuration.compareAndUpdateLocalUserConfiguration(userModel);
|
|
264
|
+
const workspaceChange = await this.loadWorkspaceConfiguration();
|
|
265
|
+
change.keys.push(...workspaceChange.keys);
|
|
266
|
+
change.overrides.push(...workspaceChange.overrides);
|
|
267
|
+
for (const folder of this.workspaceService.getWorkspace().folders) {
|
|
268
|
+
const folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
|
|
269
|
+
if (folderConfiguration) {
|
|
270
|
+
const folderModel = await folderConfiguration.loadConfiguration();
|
|
271
|
+
const folderChange = this._configuration.compareAndUpdateFolderConfiguration(folder.uri, folderModel);
|
|
272
|
+
change.keys.push(...folderChange.keys);
|
|
273
|
+
change.overrides.push(...folderChange.overrides);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.USER);
|
|
277
|
+
}
|
|
278
|
+
reloadDefaultConfiguration() {
|
|
279
|
+
this.onDefaultConfigurationChanged(this.defaultConfiguration.reload());
|
|
280
|
+
}
|
|
281
|
+
hasCachedConfigurationDefaultsOverrides() {
|
|
282
|
+
return this.defaultConfiguration.hasCachedConfigurationDefaultsOverrides();
|
|
283
|
+
}
|
|
284
|
+
async whenRemoteConfigurationLoaded() {}
|
|
285
|
+
isSettingAppliedForAllProfiles(key) {
|
|
286
|
+
const scope = this.configurationRegistry.getConfigurationProperties()[key]?.scope;
|
|
287
|
+
if (scope && APPLICATION_SCOPES.includes(scope)) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
const allProfilesSettings = this.getValue(APPLY_ALL_PROFILES_SETTING) ?? [];
|
|
291
|
+
return Array.isArray(allProfilesSettings) && allProfilesSettings.includes(key);
|
|
292
|
+
}
|
|
293
|
+
initAgentsWindowReadOnlyKeys() {
|
|
294
|
+
const properties = this.configurationRegistry.getConfigurationProperties();
|
|
295
|
+
for (const key in properties) {
|
|
296
|
+
if (properties[key].agentsWindow?.readOnly) {
|
|
297
|
+
this.agentsWindowReadOnlyKeys.add(key);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
updateAgentsWindowReadOnlyKeys(changedProperties) {
|
|
302
|
+
const properties = this.configurationRegistry.getConfigurationProperties();
|
|
303
|
+
for (const key of changedProperties) {
|
|
304
|
+
if (properties[key]?.agentsWindow?.readOnly) {
|
|
305
|
+
this.agentsWindowReadOnlyKeys.add(key);
|
|
306
|
+
} else {
|
|
307
|
+
this.agentsWindowReadOnlyKeys.delete(key);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
onDefaultConfigurationChanged(defaults, properties) {
|
|
312
|
+
if (properties) {
|
|
313
|
+
this.updateAgentsWindowReadOnlyKeys(properties);
|
|
314
|
+
}
|
|
315
|
+
const previousData = this._configuration.toData();
|
|
316
|
+
const change = this._configuration.compareAndUpdateDefaultConfiguration(defaults, properties);
|
|
317
|
+
this._configuration.updateLocalUserConfiguration(this.userConfiguration.reparse({
|
|
318
|
+
exclude: [...this.agentsWindowReadOnlyKeys]
|
|
319
|
+
}));
|
|
320
|
+
this._configuration.updateWorkspaceConfiguration(this.workspaceConfiguration.reparseWorkspaceSettings({
|
|
321
|
+
exclude: [...this.agentsWindowReadOnlyKeys]
|
|
322
|
+
}));
|
|
323
|
+
for (const folder of this.workspaceService.getWorkspace().folders) {
|
|
324
|
+
const folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
|
|
325
|
+
if (folderConfiguration) {
|
|
326
|
+
this._configuration.updateFolderConfiguration(folder.uri, folderConfiguration.reparse());
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.DEFAULT);
|
|
330
|
+
}
|
|
331
|
+
onPolicyConfigurationChanged(policyConfiguration) {
|
|
332
|
+
const previousData = this._configuration.toData();
|
|
333
|
+
const change = this._configuration.compareAndUpdatePolicyConfiguration(policyConfiguration);
|
|
334
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.DEFAULT);
|
|
335
|
+
}
|
|
336
|
+
onUserConfigurationChanged(userConfiguration) {
|
|
337
|
+
const previousData = this._configuration.toData();
|
|
338
|
+
const change = this._configuration.compareAndUpdateLocalUserConfiguration(userConfiguration);
|
|
339
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.USER);
|
|
340
|
+
}
|
|
341
|
+
async onWorkspaceConfigurationChanged() {
|
|
342
|
+
const previousData = this._configuration.toData();
|
|
343
|
+
const change = await this.loadWorkspaceConfiguration();
|
|
344
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.WORKSPACE);
|
|
345
|
+
}
|
|
346
|
+
async loadWorkspaceConfiguration() {
|
|
347
|
+
await this.workspaceConfiguration.reload();
|
|
348
|
+
this.workspaceConfiguration.reparseWorkspaceSettings({
|
|
349
|
+
exclude: [...this.agentsWindowReadOnlyKeys]
|
|
350
|
+
});
|
|
351
|
+
return this._configuration.compareAndUpdateWorkspaceConfiguration(this.workspaceConfiguration.getConfiguration());
|
|
352
|
+
}
|
|
353
|
+
onWorkspaceFoldersChanged(e) {
|
|
354
|
+
const previousData = this._configuration.toData();
|
|
355
|
+
const keys = [];
|
|
356
|
+
const overrides = [];
|
|
357
|
+
for (const folder of e.removed) {
|
|
358
|
+
const change = this._configuration.compareAndDeleteFolderConfiguration(folder.uri);
|
|
359
|
+
keys.push(...change.keys);
|
|
360
|
+
overrides.push(...change.overrides);
|
|
361
|
+
this.cachedFolderConfigs.deleteAndDispose(folder.uri);
|
|
362
|
+
}
|
|
363
|
+
if (keys.length || overrides.length) {
|
|
364
|
+
this.triggerConfigurationChange({
|
|
365
|
+
keys,
|
|
366
|
+
overrides
|
|
367
|
+
}, previousData, ConfigurationTarget.WORKSPACE_FOLDER);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
onWorkspaceFolderConfigurationChanged(folder) {
|
|
371
|
+
const folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
|
|
372
|
+
if (folderConfiguration) {
|
|
373
|
+
folderConfiguration.loadConfiguration().then(configurationModel => {
|
|
374
|
+
const previousData = this._configuration.toData();
|
|
375
|
+
const change = this._configuration.compareAndUpdateFolderConfiguration(folder.uri, configurationModel);
|
|
376
|
+
this.triggerConfigurationChange(change, previousData, ConfigurationTarget.WORKSPACE_FOLDER);
|
|
377
|
+
}, onUnexpectedError);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async loadFolderConfigurations(folders) {
|
|
381
|
+
for (const folder of folders) {
|
|
382
|
+
let folderConfiguration = this.cachedFolderConfigs.get(folder.uri);
|
|
383
|
+
if (!folderConfiguration) {
|
|
384
|
+
folderConfiguration = ( new FolderConfiguration(
|
|
385
|
+
false,
|
|
386
|
+
folder,
|
|
387
|
+
FOLDER_CONFIG_FOLDER_NAME,
|
|
388
|
+
WorkbenchState.WORKSPACE,
|
|
389
|
+
true,
|
|
390
|
+
this.fileService,
|
|
391
|
+
this.uriIdentityService,
|
|
392
|
+
this.logService,
|
|
393
|
+
{
|
|
394
|
+
needsCaching: () => false,
|
|
395
|
+
read: async () => "",
|
|
396
|
+
write: async () => {},
|
|
397
|
+
remove: async () => {}
|
|
398
|
+
}
|
|
399
|
+
));
|
|
400
|
+
folderConfiguration.addRelated(
|
|
401
|
+
folderConfiguration.onDidChange(() => this.onWorkspaceFolderConfigurationChanged(folder))
|
|
402
|
+
);
|
|
403
|
+
this.cachedFolderConfigs.set(folder.uri, folderConfiguration);
|
|
404
|
+
}
|
|
405
|
+
const configurationModel = await folderConfiguration.loadConfiguration();
|
|
406
|
+
this._configuration.updateFolderConfiguration(folder.uri, configurationModel);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
triggerConfigurationChange(change, previousData, target) {
|
|
410
|
+
if (change.keys.length) {
|
|
411
|
+
const workspace = this.workspaceService.getWorkspace();
|
|
412
|
+
const event = ( new ConfigurationChangeEvent(change, {
|
|
413
|
+
data: previousData,
|
|
414
|
+
workspace
|
|
415
|
+
}, this._configuration, workspace, this.logService));
|
|
416
|
+
event.source = target;
|
|
417
|
+
this._onDidChangeConfiguration.fire(event);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
class ConfigurationEditing {
|
|
422
|
+
constructor(fileService, configurationService) {
|
|
423
|
+
this.fileService = fileService;
|
|
424
|
+
this.configurationService = configurationService;
|
|
425
|
+
this.queue = ( new Queue());
|
|
426
|
+
}
|
|
427
|
+
write(settingsResource, path, value) {
|
|
428
|
+
return this.queue.queue(() => this.doWriteConfiguration(settingsResource, path, value));
|
|
429
|
+
}
|
|
430
|
+
async doWriteConfiguration(settingsResource, path, value) {
|
|
431
|
+
let content;
|
|
432
|
+
try {
|
|
433
|
+
const fileContent = await this.fileService.readFile(settingsResource);
|
|
434
|
+
content = ( fileContent.value.toString());
|
|
435
|
+
} catch (error) {
|
|
436
|
+
if (error.fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
|
|
437
|
+
content = "{}";
|
|
438
|
+
} else {
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const parseErrors = [];
|
|
443
|
+
parse(content, parseErrors, {
|
|
444
|
+
allowTrailingComma: true,
|
|
445
|
+
allowEmptyContent: true
|
|
446
|
+
});
|
|
447
|
+
if (parseErrors.length > 0) {
|
|
448
|
+
throw ( new Error(
|
|
449
|
+
"Unable to write into the settings file. Please open the file to correct errors/warnings in the file and try again."
|
|
450
|
+
));
|
|
451
|
+
}
|
|
452
|
+
const edits = this.getEdits(content, path, value);
|
|
453
|
+
content = applyEdits(content, edits);
|
|
454
|
+
await this.fileService.writeFile(settingsResource, VSBuffer.fromString(content));
|
|
455
|
+
}
|
|
456
|
+
getEdits(content, path, value) {
|
|
457
|
+
const {
|
|
458
|
+
tabSize,
|
|
459
|
+
insertSpaces,
|
|
460
|
+
eol
|
|
461
|
+
} = this.formattingOptions;
|
|
462
|
+
if (!path.length) {
|
|
463
|
+
const newContent = JSON.stringify(value, null, insertSpaces ? " ".repeat(tabSize) : "\t");
|
|
464
|
+
return [{
|
|
465
|
+
content: newContent,
|
|
466
|
+
length: content.length,
|
|
467
|
+
offset: 0
|
|
468
|
+
}];
|
|
469
|
+
}
|
|
470
|
+
return setProperty(content, path, value, {
|
|
471
|
+
tabSize,
|
|
472
|
+
insertSpaces,
|
|
473
|
+
eol
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
get formattingOptions() {
|
|
477
|
+
if (!this._formattingOptions) {
|
|
478
|
+
let eol = OS === OperatingSystem.Linux || OS === OperatingSystem.Macintosh ? "\n" : "\r\n";
|
|
479
|
+
const configuredEol = this.configurationService.getValue("files.eol", {
|
|
480
|
+
overrideIdentifier: "jsonc"
|
|
481
|
+
});
|
|
482
|
+
if (configuredEol && typeof configuredEol === "string" && configuredEol !== "auto") {
|
|
483
|
+
eol = configuredEol;
|
|
484
|
+
}
|
|
485
|
+
this._formattingOptions = {
|
|
486
|
+
eol,
|
|
487
|
+
insertSpaces: !!this.configurationService.getValue("editor.insertSpaces", {
|
|
488
|
+
overrideIdentifier: "jsonc"
|
|
489
|
+
}),
|
|
490
|
+
tabSize: this.configurationService.getValue("editor.tabSize", {
|
|
491
|
+
overrideIdentifier: "jsonc"
|
|
492
|
+
})
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return this._formattingOptions;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export { ConfigurationService };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Event } from "@codingame/monaco-vscode-api/vscode/vs/base/common/event";
|
|
2
|
+
import { URI } from "@codingame/monaco-vscode-api/vscode/vs/base/common/uri";
|
|
3
|
+
import { IUriIdentityService } from "@codingame/monaco-vscode-api/vscode/vs/platform/uriIdentity/common/uriIdentity.service";
|
|
4
|
+
import { IWorkspace, IWorkspaceFoldersChangeEvent, IWorkspaceFoldersWillChangeEvent, IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, IWorkspaceFolder, WorkbenchState } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace";
|
|
5
|
+
import { IWorkspaceContextService } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service";
|
|
6
|
+
import { IWorkspaceFolderCreationData } from "@codingame/monaco-vscode-api/vscode/vs/platform/workspaces/common/workspaces";
|
|
7
|
+
import { IWorkspaceEditingService } from "@codingame/monaco-vscode-api/vscode/vs/workbench/services/workspaces/common/workspaceEditing.service";
|
|
8
|
+
import { Disposable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle";
|
|
9
|
+
export declare class SessionsWorkspaceContextService extends Disposable implements IWorkspaceContextService, IWorkspaceEditingService {
|
|
10
|
+
private readonly uriIdentityService;
|
|
11
|
+
readonly _serviceBrand: undefined;
|
|
12
|
+
readonly onDidChangeWorkbenchState: Event<any>;
|
|
13
|
+
readonly onDidChangeWorkspaceName: Event<any>;
|
|
14
|
+
readonly onDidEnterWorkspace: Event<any>;
|
|
15
|
+
private readonly _onWillChangeWorkspaceFolders;
|
|
16
|
+
readonly onWillChangeWorkspaceFolders: Event<IWorkspaceFoldersWillChangeEvent>;
|
|
17
|
+
private readonly _onDidChangeWorkspaceFolders;
|
|
18
|
+
readonly onDidChangeWorkspaceFolders: Event<IWorkspaceFoldersChangeEvent>;
|
|
19
|
+
private workspace;
|
|
20
|
+
private readonly _updateFoldersQueue;
|
|
21
|
+
constructor(workspaceIdentifier: IWorkspaceIdentifier, uriIdentityService: IUriIdentityService);
|
|
22
|
+
getCompleteWorkspace(): Promise<IWorkspace>;
|
|
23
|
+
getWorkspace(): IWorkspace;
|
|
24
|
+
getWorkbenchState(): WorkbenchState;
|
|
25
|
+
hasWorkspaceData(): boolean;
|
|
26
|
+
getWorkspaceFolder(resource: URI): IWorkspaceFolder | null;
|
|
27
|
+
isInsideWorkspace(resource: URI): boolean;
|
|
28
|
+
isCurrentWorkspace(workspaceIdOrFolder: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI): boolean;
|
|
29
|
+
addFolders(foldersToAdd: IWorkspaceFolderCreationData[]): Promise<void>;
|
|
30
|
+
removeFolders(foldersToRemove: URI[]): Promise<void>;
|
|
31
|
+
updateFolders(index: number, deleteCount?: number, foldersToAddCandidates?: IWorkspaceFolderCreationData[]): Promise<void>;
|
|
32
|
+
enterWorkspace(_path: URI): Promise<void>;
|
|
33
|
+
createAndEnterWorkspace(_folders: IWorkspaceFolderCreationData[], _path?: URI): Promise<void>;
|
|
34
|
+
saveAndEnterWorkspace(_path: URI): Promise<void>;
|
|
35
|
+
copyWorkspaceSettings(_toWorkspace: IWorkspaceIdentifier): Promise<void>;
|
|
36
|
+
pickNewWorkspacePath(): Promise<URI | undefined>;
|
|
37
|
+
private doUpdateFolders;
|
|
38
|
+
private _doUpdateFolders;
|
|
39
|
+
}
|