Skip to content

Commit 69e9593

Browse files
committed
1 parent 53e3e9e commit 69e9593

4 files changed

Lines changed: 210 additions & 12 deletions

File tree

src/vs/platform/configuration/common/configuration.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export class Configuration<T> {
207207

208208
private _globalConfiguration: ConfigurationModel<T>;
209209
private _workspaceConsolidatedConfiguration: ConfigurationModel<T>;
210+
private _legacyWorkspaceConsolidatedConfiguration: ConfigurationModel<T>;
210211
protected _foldersConsolidatedConfigurations: StrictResourceMap<ConfigurationModel<T>>;
211212

212213
constructor(protected _defaults: ConfigurationModel<T>, protected _user: ConfigurationModel<T>, protected _workspaceConfiguration: ConfigurationModel<T> = new ConfigurationModel<T>(), protected folders: StrictResourceMap<ConfigurationModel<T>> = new StrictResourceMap<ConfigurationModel<T>>(), protected _workspace?: Workspace) {
@@ -224,6 +225,7 @@ export class Configuration<T> {
224225
protected merge(): void {
225226
this._globalConfiguration = new ConfigurationModel<T>().merge(this._defaults).merge(this._user);
226227
this._workspaceConsolidatedConfiguration = new ConfigurationModel<T>().merge(this._globalConfiguration).merge(this._workspaceConfiguration);
228+
this._legacyWorkspaceConsolidatedConfiguration = null;
227229
this._foldersConsolidatedConfigurations = new StrictResourceMap<ConfigurationModel<T>>();
228230
for (const folder of this.folders.keys()) {
229231
this.mergeFolder(folder);
@@ -252,6 +254,20 @@ export class Configuration<T> {
252254
};
253255
}
254256

257+
lookupLegacy<C>(key: string): IConfigurationValue<C> {
258+
if (!this._legacyWorkspaceConsolidatedConfiguration) {
259+
this._legacyWorkspaceConsolidatedConfiguration = this._workspace ? new ConfigurationModel<any>().merge(this._workspaceConfiguration).merge(this.folders.get(this._workspace.roots[0])) : null;
260+
}
261+
const consolidateConfigurationModel = this.getConsolidateConfigurationModel({});
262+
return {
263+
default: objects.clone(getConfigurationValue<C>(this._defaults.contents, key)),
264+
user: objects.clone(getConfigurationValue<C>(this._user.contents, key)),
265+
workspace: objects.clone(this._legacyWorkspaceConsolidatedConfiguration ? getConfigurationValue<C>(this._legacyWorkspaceConsolidatedConfiguration.contents, key) : void 0),
266+
folder: void 0,
267+
value: objects.clone(getConfigurationValue<C>(consolidateConfigurationModel.contents, key))
268+
};
269+
}
270+
255271
keys(): IConfigurationKeys {
256272
return {
257273
default: this._defaults.keys,

src/vs/workbench/api/node/extHost.api.impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export function createApiFactory(
430430
return extHostConfiguration.getConfiguration(section);
431431
},
432432
getConfiguration2: proposedApiFunction(extension, (section?: string, resource?: vscode.Uri): vscode.WorkspaceConfiguration => {
433-
return extHostConfiguration.getConfiguration(section, <URI>resource);
433+
return extHostConfiguration.getConfiguration2(section, <URI>resource);
434434
}),
435435
registerTaskProvider: proposedApiFunction(extension, (type: string, provider: vscode.TaskProvider) => {
436436
return extHostTask.registerTaskProvider(extension, provider);

src/vs/workbench/api/node/extHostConfiguration.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { mixin } from 'vs/base/common/objects';
88
import URI from 'vs/base/common/uri';
99
import Event, { Emitter } from 'vs/base/common/event';
10-
import { WorkspaceConfiguration } from 'vscode';
10+
import { WorkspaceConfiguration, WorkspaceConfiguration2 } from 'vscode';
1111
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
1212
import { ExtHostConfigurationShape, MainThreadConfigurationShape } from './extHost.protocol';
1313
import { IConfigurationData, Configuration } from 'vs/platform/configuration/common/configuration';
@@ -24,6 +24,14 @@ function lookUp(tree: any, key: string) {
2424
}
2525
}
2626

27+
type ConfigurationInspect<T> = {
28+
key: string;
29+
defaultValue?: T;
30+
globalValue?: T;
31+
workspaceValue?: T;
32+
folderValue?: T;
33+
};
34+
2735
export class ExtHostConfiguration extends ExtHostConfigurationShape {
2836

2937
private readonly _onDidChangeConfiguration = new Emitter<void>();
@@ -47,7 +55,15 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
4755
this._onDidChangeConfiguration.fire(undefined);
4856
}
4957

50-
getConfiguration(section?: string, resource?: URI): WorkspaceConfiguration {
58+
getConfiguration(section?: string): WorkspaceConfiguration {
59+
return this._getConfiguration(section, null, true);
60+
}
61+
62+
getConfiguration2(section?: string, resource?: URI): WorkspaceConfiguration2 {
63+
return this._getConfiguration(section, resource, false);
64+
}
65+
66+
private _getConfiguration(section: string, resource: URI, legacy: boolean): WorkspaceConfiguration {
5167

5268
const config = section
5369
? lookUp(this._configuration.getValue(null, { resource }), section)
@@ -73,17 +89,20 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape {
7389
return this._proxy.$removeConfigurationOption(target, key);
7490
}
7591
},
76-
inspect: <T>(key: string): { key: string; defaultValue?: T; globalValue?: T; workspaceValue?: T, folderValue?: T } => {
92+
inspect: <T>(key: string): ConfigurationInspect<T> => {
7793
key = section ? `${section}.${key}` : key;
78-
const config = this._configuration.values()[key];
94+
const config = legacy ? this._configuration.lookupLegacy<T>(key) : this._configuration.lookup<T>(key, { resource });
7995
if (config) {
80-
return {
96+
const inspect: ConfigurationInspect<T> = {
8197
key,
8298
defaultValue: config.default,
8399
globalValue: config.user,
84100
workspaceValue: config.workspace,
85-
folderValue: config.folder
86101
};
102+
if (!legacy) {
103+
inspect.folderValue = config.folder;
104+
}
105+
return inspect;
87106
}
88107
return undefined;
89108
}

src/vs/workbench/test/electron-browser/api/extHostConfiguration.test.ts

Lines changed: 168 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,40 @@ suite('ExtHostConfiguration', function () {
8484
assert.deepEqual(config.get('nested'), { config1: 42, config2: 'Das Pferd frisst kein Reis.' });
8585
});
8686

87-
test('inspect', function () {
87+
test('inspect in no workspace context', function () {
88+
const testObject = new ExtHostConfiguration(
89+
new class extends MainThreadConfigurationShape { },
90+
new ExtHostWorkspace(new TestThreadService(), null),
91+
{
92+
defaults: new ConfigurationModel({
93+
'editor': {
94+
'wordWrap': 'off'
95+
}
96+
}, ['editor.wordWrap']),
97+
user: new ConfigurationModel({
98+
'editor': {
99+
'wordWrap': 'on'
100+
}
101+
}, ['editor.wordWrap']),
102+
workspace: new ConfigurationModel({}, []),
103+
folders: Object.create(null)
104+
}
105+
);
106+
107+
let actual = testObject.getConfiguration().inspect('editor.wordWrap');
108+
assert.equal(actual.defaultValue, 'off');
109+
assert.equal(actual.globalValue, 'on');
110+
assert.equal(actual.workspaceValue, undefined);
111+
assert.ok(Object.keys(actual).indexOf('folderValue') === -1);
112+
113+
actual = testObject.getConfiguration('editor').inspect('wordWrap');
114+
assert.equal(actual.defaultValue, 'off');
115+
assert.equal(actual.globalValue, 'on');
116+
assert.equal(actual.workspaceValue, undefined);
117+
assert.ok(Object.keys(actual).indexOf('folderValue') === -1);
118+
});
119+
120+
test('inspect in single root context', function () {
88121
const workspaceUri = URI.file('foo');
89122
const folders = Object.create(null);
90123
const workspace = new ConfigurationModel({
@@ -116,10 +149,140 @@ suite('ExtHostConfiguration', function () {
116149
}
117150
);
118151

119-
const actual = testObject.getConfiguration().inspect('editor.wordWrap');
120-
assert.equal(actual.defaultValue, 'off');
121-
assert.equal(actual.globalValue, 'on');
122-
assert.equal(actual.workspaceValue, 'bounded');
152+
let actual1 = testObject.getConfiguration().inspect('editor.wordWrap');
153+
assert.equal(actual1.defaultValue, 'off');
154+
assert.equal(actual1.globalValue, 'on');
155+
assert.equal(actual1.workspaceValue, 'bounded');
156+
assert.ok(Object.keys(actual1).indexOf('folderValue') === -1);
157+
158+
actual1 = testObject.getConfiguration('editor').inspect('wordWrap');
159+
assert.equal(actual1.defaultValue, 'off');
160+
assert.equal(actual1.globalValue, 'on');
161+
assert.equal(actual1.workspaceValue, 'bounded');
162+
assert.ok(Object.keys(actual1).indexOf('folderValue') === -1);
163+
164+
let actual2 = testObject.getConfiguration2(null, workspaceUri).inspect('editor.wordWrap');
165+
assert.equal(actual2.defaultValue, 'off');
166+
assert.equal(actual2.globalValue, 'on');
167+
assert.equal(actual2.workspaceValue, 'bounded');
168+
assert.equal(actual2.folderValue, 'bounded');
169+
170+
actual2 = testObject.getConfiguration2('editor', workspaceUri).inspect('wordWrap');
171+
assert.equal(actual2.defaultValue, 'off');
172+
assert.equal(actual2.globalValue, 'on');
173+
assert.equal(actual2.workspaceValue, 'bounded');
174+
assert.equal(actual2.folderValue, 'bounded');
175+
});
176+
177+
test('inspect in multi root context', function () {
178+
const workspace = new ConfigurationModel({
179+
'editor': {
180+
'wordWrap': 'bounded'
181+
}
182+
}, ['editor.wordWrap']);
183+
184+
const firstRoot = URI.file('foo1');
185+
const secondRoot = URI.file('foo2');
186+
const thirdRoot = URI.file('foo3');
187+
const folders = Object.create(null);
188+
folders[firstRoot.toString()] = new ConfigurationModel({
189+
'editor': {
190+
'wordWrap': 'off',
191+
'lineNumbers': 'relative'
192+
}
193+
}, ['editor.wordWrap']);
194+
folders[secondRoot.toString()] = new ConfigurationModel({
195+
'editor': {
196+
'wordWrap': 'on'
197+
}
198+
}, ['editor.wordWrap']);
199+
folders[thirdRoot.toString()] = new ConfigurationModel({}, []);
200+
201+
const testObject = new ExtHostConfiguration(
202+
new class extends MainThreadConfigurationShape { },
203+
new ExtHostWorkspace(new TestThreadService(), {
204+
'id': 'foo',
205+
'roots': [firstRoot, secondRoot],
206+
'name': 'foo'
207+
}),
208+
{
209+
defaults: new ConfigurationModel({
210+
'editor': {
211+
'wordWrap': 'off',
212+
'lineNumbers': 'on'
213+
}
214+
}, ['editor.wordWrap']),
215+
user: new ConfigurationModel({
216+
'editor': {
217+
'wordWrap': 'on'
218+
}
219+
}, ['editor.wordWrap']),
220+
workspace,
221+
folders
222+
}
223+
);
224+
225+
let actual1 = testObject.getConfiguration().inspect('editor.wordWrap');
226+
assert.equal(actual1.defaultValue, 'off');
227+
assert.equal(actual1.globalValue, 'on');
228+
assert.equal(actual1.workspaceValue, 'off');
229+
assert.ok(Object.keys(actual1).indexOf('folderValue') === -1);
230+
231+
actual1 = testObject.getConfiguration('editor').inspect('wordWrap');
232+
assert.equal(actual1.defaultValue, 'off');
233+
assert.equal(actual1.globalValue, 'on');
234+
assert.equal(actual1.workspaceValue, 'off');
235+
assert.ok(Object.keys(actual1).indexOf('folderValue') === -1);
236+
237+
actual1 = testObject.getConfiguration('editor').inspect('lineNumbers');
238+
assert.equal(actual1.defaultValue, 'on');
239+
assert.equal(actual1.globalValue, undefined);
240+
assert.equal(actual1.workspaceValue, 'relative');
241+
assert.ok(Object.keys(actual1).indexOf('folderValue') === -1);
242+
243+
let actual2 = testObject.getConfiguration2(null, firstRoot).inspect('editor.wordWrap');
244+
assert.equal(actual2.defaultValue, 'off');
245+
assert.equal(actual2.globalValue, 'on');
246+
assert.equal(actual2.workspaceValue, 'bounded');
247+
assert.equal(actual2.folderValue, 'off');
248+
249+
actual2 = testObject.getConfiguration2('editor', firstRoot).inspect('wordWrap');
250+
assert.equal(actual2.defaultValue, 'off');
251+
assert.equal(actual2.globalValue, 'on');
252+
assert.equal(actual2.workspaceValue, 'bounded');
253+
assert.equal(actual2.folderValue, 'off');
254+
255+
actual2 = testObject.getConfiguration2('editor', firstRoot).inspect('lineNumbers');
256+
assert.equal(actual2.defaultValue, 'on');
257+
assert.equal(actual2.globalValue, undefined);
258+
assert.equal(actual2.workspaceValue, undefined);
259+
assert.equal(actual2.folderValue, 'relative');
260+
261+
actual2 = testObject.getConfiguration2(null, secondRoot).inspect('editor.wordWrap');
262+
assert.equal(actual2.defaultValue, 'off');
263+
assert.equal(actual2.globalValue, 'on');
264+
assert.equal(actual2.workspaceValue, 'bounded');
265+
assert.equal(actual2.folderValue, 'on');
266+
267+
actual2 = testObject.getConfiguration2('editor', secondRoot).inspect('wordWrap');
268+
assert.equal(actual2.defaultValue, 'off');
269+
assert.equal(actual2.globalValue, 'on');
270+
assert.equal(actual2.workspaceValue, 'bounded');
271+
assert.equal(actual2.folderValue, 'on');
272+
273+
actual2 = testObject.getConfiguration2(null, thirdRoot).inspect('editor.wordWrap');
274+
assert.equal(actual2.defaultValue, 'off');
275+
assert.equal(actual2.globalValue, 'on');
276+
assert.equal(actual2.workspaceValue, 'bounded');
277+
assert.ok(Object.keys(actual2).indexOf('folderValue') !== -1);
278+
assert.equal(actual2.folderValue, undefined);
279+
280+
actual2 = testObject.getConfiguration2('editor', thirdRoot).inspect('wordWrap');
281+
assert.equal(actual2.defaultValue, 'off');
282+
assert.equal(actual2.globalValue, 'on');
283+
assert.equal(actual2.workspaceValue, 'bounded');
284+
assert.ok(Object.keys(actual2).indexOf('folderValue') !== -1);
285+
assert.equal(actual2.folderValue, undefined);
123286
});
124287

125288
test('getConfiguration vs get', function () {

0 commit comments

Comments
 (0)