Skip to content

Commit 044c8ed

Browse files
committed
toWorkspaceFolders takes workspaceConfigPath
1 parent e5f694e commit 044c8ed

7 files changed

Lines changed: 28 additions & 26 deletions

File tree

src/vs/code/test/node/windowsFinder.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1010
import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
1111
import { URI } from 'vs/base/common/uri';
1212
import { getPathFromAmdModule } from 'vs/base/common/amd';
13-
import { dirname } from 'vs/base/common/resources';
1413

1514
const fixturesFolder = getPathFromAmdModule(require, './fixtures');
1615

@@ -19,7 +18,7 @@ const testWorkspace: IWorkspaceIdentifier = {
1918
configPath: URI.file(path.join(fixturesFolder, 'workspaces.json'))
2019
};
2120

22-
const testWorkspaceFolders = toWorkspaceFolders([{ path: path.join(fixturesFolder, 'vscode_workspace_1_folder') }, { path: path.join(fixturesFolder, 'vscode_workspace_2_folder') }], dirname(testWorkspace.configPath));
21+
const testWorkspaceFolders = toWorkspaceFolders([{ path: path.join(fixturesFolder, 'vscode_workspace_1_folder') }, { path: path.join(fixturesFolder, 'vscode_workspace_2_folder') }], testWorkspace.configPath);
2322

2423
function options(custom?: Partial<IBestWindowOrFolderOptions<ISimpleWindow>>): IBestWindowOrFolderOptions<ISimpleWindow> {
2524
return {

src/vs/editor/contrib/snippet/test/snippetVariables.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,8 @@ suite('Snippet Variables Resolver', function () {
332332
assertVariableResolve(resolver, 'WORKSPACE_NAME', 'folderName');
333333

334334
// workspace with config
335-
const workspaceFile = URI.file('testWorkspace.code-workspace');
336-
const workspaceDir = URI.file('workspace');
337-
workspace = new Workspace('', toWorkspaceFolders([{ path: 'folderName' }], workspaceDir), workspaceFile);
335+
const workspaceConfigPath = URI.file('testWorkspace.code-workspace');
336+
workspace = new Workspace('', toWorkspaceFolders([{ path: 'folderName' }], workspaceConfigPath), workspaceConfigPath);
338337
assertVariableResolve(resolver, 'WORKSPACE_NAME', 'testWorkspace');
339338
});
340339
});

src/vs/platform/workspace/common/workspace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ export function toWorkspaceFolder(resource: URI): WorkspaceFolder {
226226
return new WorkspaceFolder({ uri: resource, index: 0, name: resources.basenameOrAuthority(resource) }, { uri: resource.toString() });
227227
}
228228

229-
export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo: URI): WorkspaceFolder[] {
229+
export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], workspaceConfigFile: URI): WorkspaceFolder[] {
230230
let result: WorkspaceFolder[] = [];
231231
let seen: { [uri: string]: boolean } = Object.create(null);
232232

233+
const relativeTo = resources.dirname(workspaceConfigFile);
233234
for (let configuredFolder of configuredFolders) {
234235
let uri: URI | null = null;
235236
if (isRawFileWorkspaceFolder(configuredFolder)) {

src/vs/platform/workspace/test/common/workspace.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { IRawFileWorkspaceFolder } from 'vs/platform/workspaces/common/workspace
1010

1111
suite('Workspace', () => {
1212

13+
const workspaceConfigPath = URI.file('/src/test.code-workspace');
14+
1315
test('getFolder returns the folder with given uri', () => {
1416
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 2 });
1517
let testObject = new Workspace('', [new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 0 }), expected, new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
@@ -46,7 +48,7 @@ suite('Workspace', () => {
4648
});
4749

4850
test('toWorkspaceFolders with single absolute folder', () => {
49-
const actual = toWorkspaceFolders([{ path: '/src/test' }], URI.file('/workspaces'));
51+
const actual = toWorkspaceFolders([{ path: '/src/test' }], workspaceConfigPath);
5052

5153
assert.equal(actual.length, 1);
5254
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
@@ -56,7 +58,7 @@ suite('Workspace', () => {
5658
});
5759

5860
test('toWorkspaceFolders with single relative folder', () => {
59-
const actual = toWorkspaceFolders([{ path: './test' }], URI.file('src'));
61+
const actual = toWorkspaceFolders([{ path: './test' }], workspaceConfigPath);
6062

6163
assert.equal(actual.length, 1);
6264
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
@@ -66,7 +68,7 @@ suite('Workspace', () => {
6668
});
6769

6870
test('toWorkspaceFolders with single absolute folder with name', () => {
69-
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }], URI.file('/workspaces'));
71+
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }], workspaceConfigPath);
7072

7173
assert.equal(actual.length, 1);
7274

@@ -77,7 +79,7 @@ suite('Workspace', () => {
7779
});
7880

7981
test('toWorkspaceFolders with multiple unique absolute folders', () => {
80-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }], URI.file('/workspaces'));
82+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }], workspaceConfigPath);
8183

8284
assert.equal(actual.length, 3);
8385
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
@@ -97,7 +99,7 @@ suite('Workspace', () => {
9799
});
98100

99101
test('toWorkspaceFolders with multiple unique absolute folders with names', () => {
100-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }], URI.file('/workspaces'));
102+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }], workspaceConfigPath);
101103

102104
assert.equal(actual.length, 3);
103105
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
@@ -117,7 +119,7 @@ suite('Workspace', () => {
117119
});
118120

119121
test('toWorkspaceFolders with multiple unique absolute and relative folders', () => {
120-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/abc/test3', name: 'noName' }, { path: './test1' }], URI.file('src'));
122+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/abc/test3', name: 'noName' }, { path: './test1' }], workspaceConfigPath);
121123

122124
assert.equal(actual.length, 3);
123125
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
@@ -137,7 +139,7 @@ suite('Workspace', () => {
137139
});
138140

139141
test('toWorkspaceFolders with multiple absolute folders with duplicates', () => {
140-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }], URI.file('/workspaces'));
142+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }], workspaceConfigPath);
141143

142144
assert.equal(actual.length, 2);
143145
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
@@ -152,7 +154,7 @@ suite('Workspace', () => {
152154
});
153155

154156
test('toWorkspaceFolders with multiple absolute and relative folders with duplicates', () => {
155-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], URI.file('src'));
157+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], workspaceConfigPath);
156158

157159
assert.equal(actual.length, 3);
158160
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
@@ -172,7 +174,7 @@ suite('Workspace', () => {
172174
});
173175

174176
test('toWorkspaceFolders with multiple absolute and relative folders with invalid paths', () => {
175-
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], URI.file('src'));
177+
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], workspaceConfigPath);
176178

177179
assert.equal(actual.length, 3);
178180
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);

src/vs/platform/workspaces/electron-main/workspacesMainService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
1717
import { URI } from 'vs/base/common/uri';
1818
import { Schemas } from 'vs/base/common/network';
1919
import { Disposable } from 'vs/base/common/lifecycle';
20-
import { originalFSPath, dirname as resourcesDirname, isEqualOrParent, joinPath } from 'vs/base/common/resources';
20+
import { originalFSPath, isEqualOrParent, joinPath } from 'vs/base/common/resources';
2121

2222
export interface IStoredWorkspace {
2323
folders: IStoredWorkspaceFolder[];
@@ -71,7 +71,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
7171
return {
7272
id: workspaceIdentifier.id,
7373
configPath: workspaceIdentifier.configPath,
74-
folders: toWorkspaceFolders(workspace.folders, resourcesDirname(path)),
74+
folders: toWorkspaceFolders(workspace.folders, workspaceIdentifier.configPath),
7575
remoteAuthority: workspace.remoteAuthority
7676
};
7777
} catch (error) {

src/vs/workbench/contrib/search/test/common/queryBuilder.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ suite('QueryBuilder', () => {
2424
const PATTERN_INFO: IPatternInfo = { pattern: 'a' };
2525
const ROOT_1 = fixPath('/foo/root1');
2626
const ROOT_1_URI = getUri(ROOT_1);
27-
const WS_FOLDER = getUri('/bar'); // location of the workspace file (not important except that it is a file URI)
27+
const WS_CONFIG_PATH = getUri('/bar/test.code-workspace'); // location of the workspace file (not important except that it is a file URI)
2828

2929
let instantiationService: TestInstantiationService;
3030
let queryBuilder: QueryBuilder;
@@ -278,7 +278,7 @@ suite('QueryBuilder', () => {
278278
const ROOT_2_URI = getUri(ROOT_2);
279279
const ROOT_3 = fixPath('/project/root3');
280280
const ROOT_3_URI = getUri(ROOT_3);
281-
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: ROOT_2_URI.fsPath }, { path: ROOT_3_URI.fsPath }], WS_FOLDER);
281+
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: ROOT_2_URI.fsPath }, { path: ROOT_3_URI.fsPath }], WS_CONFIG_PATH);
282282
mockWorkspace.configuration = uri.file(fixPath('/config'));
283283

284284
mockConfigService.setUserConfiguration('search', {
@@ -690,7 +690,7 @@ suite('QueryBuilder', () => {
690690

691691
test('relative includes w/two root folders', () => {
692692
const ROOT_2 = '/project/root2';
693-
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }], WS_FOLDER);
693+
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }], WS_CONFIG_PATH);
694694
mockWorkspace.configuration = uri.file(fixPath('config'));
695695

696696
const cases: [string, ISearchPathsInfo][] = [
@@ -731,7 +731,7 @@ suite('QueryBuilder', () => {
731731
test('include ./foldername', () => {
732732
const ROOT_2 = '/project/root2';
733733
const ROOT_1_FOLDERNAME = 'foldername';
734-
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath, name: ROOT_1_FOLDERNAME }, { path: getUri(ROOT_2).fsPath }], WS_FOLDER);
734+
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath, name: ROOT_1_FOLDERNAME }, { path: getUri(ROOT_2).fsPath }], WS_CONFIG_PATH);
735735
mockWorkspace.configuration = uri.file(fixPath('config'));
736736

737737
const cases: [string, ISearchPathsInfo][] = [
@@ -759,7 +759,7 @@ suite('QueryBuilder', () => {
759759
test('relative includes w/multiple ambiguous root folders', () => {
760760
const ROOT_2 = '/project/rootB';
761761
const ROOT_3 = '/otherproject/rootB';
762-
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }, { path: getUri(ROOT_3).fsPath }], WS_FOLDER);
762+
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }, { path: getUri(ROOT_3).fsPath }], WS_CONFIG_PATH);
763763
mockWorkspace.configuration = uri.file(fixPath('/config'));
764764

765765
const cases: [string, ISearchPathsInfo][] = [

src/vs/workbench/services/configuration/browser/configurationService.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
181181
if (foldersToAdd.length) {
182182

183183
// Recompute current workspace folders if we have folders to add
184-
const workspaceConfigFolder = dirname(this.getWorkspace().configuration!);
185-
currentWorkspaceFolders = toWorkspaceFolders(newStoredFolders, workspaceConfigFolder);
184+
const workspaceConfigPath = this.getWorkspace().configuration!;
185+
const workspaceConfigFolder = dirname(workspaceConfigPath);
186+
currentWorkspaceFolders = toWorkspaceFolders(newStoredFolders, workspaceConfigPath);
186187
const currentWorkspaceFolderUris = currentWorkspaceFolders.map(folder => folder.uri);
187188

188189
const storedFoldersToAdd: IStoredWorkspaceFolder[] = [];
@@ -329,7 +330,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
329330
return this.workspaceConfiguration.load({ id: workspaceIdentifier.id, configPath: workspaceIdentifier.configPath })
330331
.then(() => {
331332
const workspaceConfigPath = workspaceIdentifier.configPath;
332-
const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), dirname(workspaceConfigPath));
333+
const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), workspaceConfigPath);
333334
const workspaceId = workspaceIdentifier.id;
334335
const workspace = new Workspace(workspaceId, workspaceFolders, workspaceConfigPath);
335336
if (this.workspaceConfiguration.loaded) {
@@ -549,7 +550,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
549550
private onWorkspaceConfigurationChanged(): Promise<void> {
550551
if (this.workspace && this.workspace.configuration && this._configuration) {
551552
const workspaceConfigurationChangeEvent = this._configuration.compareAndUpdateWorkspaceConfiguration(this.workspaceConfiguration.getConfiguration());
552-
let configuredFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), dirname(this.workspace.configuration));
553+
let configuredFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), this.workspace.configuration);
553554
const changes = this.compareFolders(this.workspace.folders, configuredFolders);
554555
if (changes.added.length || changes.removed.length || changes.changed.length) {
555556
this.workspace.folders = configuredFolders;

0 commit comments

Comments
 (0)