Skip to content

Commit d7b54f7

Browse files
authored
1 parent dee7ada commit d7b54f7

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

src/vs/editor/common/services/textResourceConfigurationService.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,8 @@ export class TextResourceConfigurationService extends Disposable implements ITex
4343
if (configurationTarget === undefined) {
4444
configurationTarget = this.deriveConfigurationTarget(configurationValue, language);
4545
}
46-
switch (configurationTarget) {
47-
case ConfigurationTarget.MEMORY:
48-
return this._updateValue(key, value, configurationTarget, configurationValue.memory?.override, resource, language);
49-
case ConfigurationTarget.WORKSPACE_FOLDER:
50-
return this._updateValue(key, value, configurationTarget, configurationValue.workspaceFolder?.override, resource, language);
51-
case ConfigurationTarget.WORKSPACE:
52-
return this._updateValue(key, value, configurationTarget, configurationValue.workspace?.override, resource, language);
53-
case ConfigurationTarget.USER_REMOTE:
54-
return this._updateValue(key, value, configurationTarget, configurationValue.userRemote?.override, resource, language);
55-
default:
56-
return this._updateValue(key, value, configurationTarget, configurationValue.userLocal?.override, resource, language);
57-
}
58-
}
59-
60-
private _updateValue(key: string, value: any, configurationTarget: ConfigurationTarget, overriddenValue: any | undefined, resource: URI, language: string | null): Promise<void> {
61-
if (language && overriddenValue !== undefined) {
62-
return this.configurationService.updateValue(key, value, { resource, overrideIdentifier: language }, configurationTarget);
63-
} else {
64-
return this.configurationService.updateValue(key, value, { resource }, configurationTarget);
65-
}
46+
const overrideIdentifier = language && configurationValue.overrideIdentifiers?.includes(language) ? language : undefined;
47+
return this.configurationService.updateValue(key, value, { resource, overrideIdentifier }, configurationTarget);
6648
}
6749

6850
private deriveConfigurationTarget(configurationValue: IConfigurationValue<any>, language: string | null): ConfigurationTarget {

src/vs/editor/test/common/services/textResourceConfigurationService.test.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ suite('TextResourceConfigurationService - Update', () => {
4444
test('updateValue writes without target and overrides when no language is defined', async () => {
4545
const resource = URI.file('someFile');
4646
await testObject.updateValue(resource, 'a', 'b');
47-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER_LOCAL]);
47+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER_LOCAL]);
4848
});
4949

5050
test('updateValue writes with target and without overrides when no language is defined', async () => {
5151
const resource = URI.file('someFile');
5252
await testObject.updateValue(resource, 'a', 'b', ConfigurationTarget.USER_LOCAL);
53-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER_LOCAL]);
53+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER_LOCAL]);
5454
});
5555

5656
test('updateValue writes into given memory target without overrides', async () => {
@@ -63,7 +63,7 @@ suite('TextResourceConfigurationService - Update', () => {
6363
const resource = URI.file('someFile');
6464

6565
await testObject.updateValue(resource, 'a', 'b', ConfigurationTarget.MEMORY);
66-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.MEMORY]);
66+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.MEMORY]);
6767
});
6868

6969
test('updateValue writes into given workspace target without overrides', async () => {
@@ -76,7 +76,7 @@ suite('TextResourceConfigurationService - Update', () => {
7676
const resource = URI.file('someFile');
7777

7878
await testObject.updateValue(resource, 'a', 'b', ConfigurationTarget.WORKSPACE);
79-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.WORKSPACE]);
79+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.WORKSPACE]);
8080
});
8181

8282
test('updateValue writes into given user target without overrides', async () => {
@@ -89,7 +89,7 @@ suite('TextResourceConfigurationService - Update', () => {
8989
const resource = URI.file('someFile');
9090

9191
await testObject.updateValue(resource, 'a', 'b', ConfigurationTarget.USER);
92-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER]);
92+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER]);
9393
});
9494

9595
test('updateValue writes into given workspace folder target with overrides', async () => {
@@ -98,6 +98,7 @@ suite('TextResourceConfigurationService - Update', () => {
9898
default: { value: '1' },
9999
userLocal: { value: '2' },
100100
workspaceFolder: { value: '2', override: '1' },
101+
overrideIdentifiers: [language]
101102
};
102103
const resource = URI.file('someFile');
103104

@@ -115,7 +116,7 @@ suite('TextResourceConfigurationService - Update', () => {
115116
const resource = URI.file('someFile');
116117

117118
await testObject.updateValue(resource, 'a', 'b');
118-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.WORKSPACE_FOLDER]);
119+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.WORKSPACE_FOLDER]);
119120
});
120121

121122
test('updateValue writes into derived workspace folder target with overrides', async () => {
@@ -125,6 +126,7 @@ suite('TextResourceConfigurationService - Update', () => {
125126
userLocal: { value: '2' },
126127
workspace: { value: '2', override: '1' },
127128
workspaceFolder: { value: '2', override: '2' },
129+
overrideIdentifiers: [language]
128130
};
129131
const resource = URI.file('someFile');
130132

@@ -142,7 +144,7 @@ suite('TextResourceConfigurationService - Update', () => {
142144
const resource = URI.file('someFile');
143145

144146
await testObject.updateValue(resource, 'a', 'b');
145-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.WORKSPACE]);
147+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.WORKSPACE]);
146148
});
147149

148150
test('updateValue writes into derived workspace target with overrides', async () => {
@@ -151,6 +153,7 @@ suite('TextResourceConfigurationService - Update', () => {
151153
default: { value: '1' },
152154
userLocal: { value: '2' },
153155
workspace: { value: '2', override: '2' },
156+
overrideIdentifiers: [language]
154157
};
155158
const resource = URI.file('someFile');
156159

@@ -165,6 +168,7 @@ suite('TextResourceConfigurationService - Update', () => {
165168
userLocal: { value: '2' },
166169
workspace: { value: '2', override: '2' },
167170
workspaceFolder: { value: '2' },
171+
overrideIdentifiers: [language]
168172
};
169173
const resource = URI.file('someFile');
170174

@@ -182,7 +186,7 @@ suite('TextResourceConfigurationService - Update', () => {
182186
const resource = URI.file('someFile');
183187

184188
await testObject.updateValue(resource, 'a', 'b');
185-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER_REMOTE]);
189+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER_REMOTE]);
186190
});
187191

188192
test('updateValue writes into derived user remote target with overrides', async () => {
@@ -191,6 +195,7 @@ suite('TextResourceConfigurationService - Update', () => {
191195
default: { value: '1' },
192196
userLocal: { value: '2' },
193197
userRemote: { value: '2', override: '3' },
198+
overrideIdentifiers: [language]
194199
};
195200
const resource = URI.file('someFile');
196201

@@ -204,7 +209,8 @@ suite('TextResourceConfigurationService - Update', () => {
204209
default: { value: '1' },
205210
userLocal: { value: '2' },
206211
userRemote: { value: '2', override: '3' },
207-
workspace: { value: '3' }
212+
workspace: { value: '3' },
213+
overrideIdentifiers: [language]
208214
};
209215
const resource = URI.file('someFile');
210216

@@ -219,7 +225,8 @@ suite('TextResourceConfigurationService - Update', () => {
219225
userLocal: { value: '2', override: '1' },
220226
userRemote: { value: '2', override: '3' },
221227
workspace: { value: '3' },
222-
workspaceFolder: { value: '3' }
228+
workspaceFolder: { value: '3' },
229+
overrideIdentifiers: [language]
223230
};
224231
const resource = URI.file('someFile');
225232

@@ -236,14 +243,15 @@ suite('TextResourceConfigurationService - Update', () => {
236243
const resource = URI.file('someFile');
237244

238245
await testObject.updateValue(resource, 'a', 'b');
239-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER_LOCAL]);
246+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER_LOCAL]);
240247
});
241248

242249
test('updateValue writes into derived user target with overrides', async () => {
243250
language = 'a';
244251
configurationValue = {
245252
default: { value: '1' },
246253
userLocal: { value: '2', override: '3' },
254+
overrideIdentifiers: [language]
247255
};
248256
const resource = URI.file('someFile');
249257

@@ -256,7 +264,8 @@ suite('TextResourceConfigurationService - Update', () => {
256264
configurationValue = {
257265
default: { value: '1' },
258266
userLocal: { value: '2', override: '3' },
259-
userRemote: { value: '3' }
267+
userRemote: { value: '3' },
268+
overrideIdentifiers: [language]
260269
};
261270
const resource = URI.file('someFile');
262271

@@ -269,7 +278,8 @@ suite('TextResourceConfigurationService - Update', () => {
269278
configurationValue = {
270279
default: { value: '1' },
271280
userLocal: { value: '2', override: '3' },
272-
workspaceValue: { value: '3' }
281+
workspaceValue: { value: '3' },
282+
overrideIdentifiers: [language]
273283
};
274284
const resource = URI.file('someFile');
275285

@@ -283,7 +293,21 @@ suite('TextResourceConfigurationService - Update', () => {
283293
default: { value: '1', override: '3' },
284294
userLocal: { value: '2', override: '3' },
285295
userRemote: { value: '3' },
286-
workspaceFolderValue: { value: '3' }
296+
workspaceFolderValue: { value: '3' },
297+
overrideIdentifiers: [language]
298+
};
299+
const resource = URI.file('someFile');
300+
301+
await testObject.updateValue(resource, 'a', '2');
302+
assert.deepStrictEqual(updateArgs, ['a', '2', { resource, overrideIdentifier: language }, ConfigurationTarget.USER_LOCAL]);
303+
});
304+
305+
test('updateValue writes into derived user target when overridden in default and not in user', async () => {
306+
language = 'a';
307+
configurationValue = {
308+
default: { value: '1', override: '3' },
309+
userLocal: { value: '2' },
310+
overrideIdentifiers: [language]
287311
};
288312
const resource = URI.file('someFile');
289313

@@ -299,7 +323,7 @@ suite('TextResourceConfigurationService - Update', () => {
299323
const resource = URI.file('someFile');
300324

301325
await testObject.updateValue(resource, 'a', 'b');
302-
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource }, ConfigurationTarget.USER_LOCAL]);
326+
assert.deepStrictEqual(updateArgs, ['a', 'b', { resource, overrideIdentifier: undefined }, ConfigurationTarget.USER_LOCAL]);
303327
});
304328

305329
});

0 commit comments

Comments
 (0)