提交 044c8ed8 编写于 作者: M Martin Aeschlimann

toWorkspaceFolders takes workspaceConfigPath

上级 e5f694eb
......@@ -10,7 +10,6 @@ import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import { URI } from 'vs/base/common/uri';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { dirname } from 'vs/base/common/resources';
const fixturesFolder = getPathFromAmdModule(require, './fixtures');
......@@ -19,7 +18,7 @@ const testWorkspace: IWorkspaceIdentifier = {
configPath: URI.file(path.join(fixturesFolder, 'workspaces.json'))
};
const testWorkspaceFolders = toWorkspaceFolders([{ path: path.join(fixturesFolder, 'vscode_workspace_1_folder') }, { path: path.join(fixturesFolder, 'vscode_workspace_2_folder') }], dirname(testWorkspace.configPath));
const testWorkspaceFolders = toWorkspaceFolders([{ path: path.join(fixturesFolder, 'vscode_workspace_1_folder') }, { path: path.join(fixturesFolder, 'vscode_workspace_2_folder') }], testWorkspace.configPath);
function options(custom?: Partial<IBestWindowOrFolderOptions<ISimpleWindow>>): IBestWindowOrFolderOptions<ISimpleWindow> {
return {
......
......@@ -332,9 +332,8 @@ suite('Snippet Variables Resolver', function () {
assertVariableResolve(resolver, 'WORKSPACE_NAME', 'folderName');
// workspace with config
const workspaceFile = URI.file('testWorkspace.code-workspace');
const workspaceDir = URI.file('workspace');
workspace = new Workspace('', toWorkspaceFolders([{ path: 'folderName' }], workspaceDir), workspaceFile);
const workspaceConfigPath = URI.file('testWorkspace.code-workspace');
workspace = new Workspace('', toWorkspaceFolders([{ path: 'folderName' }], workspaceConfigPath), workspaceConfigPath);
assertVariableResolve(resolver, 'WORKSPACE_NAME', 'testWorkspace');
});
});
\ No newline at end of file
......@@ -226,10 +226,11 @@ export function toWorkspaceFolder(resource: URI): WorkspaceFolder {
return new WorkspaceFolder({ uri: resource, index: 0, name: resources.basenameOrAuthority(resource) }, { uri: resource.toString() });
}
export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo: URI): WorkspaceFolder[] {
export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], workspaceConfigFile: URI): WorkspaceFolder[] {
let result: WorkspaceFolder[] = [];
let seen: { [uri: string]: boolean } = Object.create(null);
const relativeTo = resources.dirname(workspaceConfigFile);
for (let configuredFolder of configuredFolders) {
let uri: URI | null = null;
if (isRawFileWorkspaceFolder(configuredFolder)) {
......
......@@ -10,6 +10,8 @@ import { IRawFileWorkspaceFolder } from 'vs/platform/workspaces/common/workspace
suite('Workspace', () => {
const workspaceConfigPath = URI.file('/src/test.code-workspace');
test('getFolder returns the folder with given uri', () => {
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 2 });
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', () => {
});
test('toWorkspaceFolders with single absolute folder', () => {
const actual = toWorkspaceFolders([{ path: '/src/test' }], URI.file('/workspaces'));
const actual = toWorkspaceFolders([{ path: '/src/test' }], workspaceConfigPath);
assert.equal(actual.length, 1);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
......@@ -56,7 +58,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with single relative folder', () => {
const actual = toWorkspaceFolders([{ path: './test' }], URI.file('src'));
const actual = toWorkspaceFolders([{ path: './test' }], workspaceConfigPath);
assert.equal(actual.length, 1);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
......@@ -66,7 +68,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with single absolute folder with name', () => {
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }], URI.file('/workspaces'));
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }], workspaceConfigPath);
assert.equal(actual.length, 1);
......@@ -77,7 +79,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple unique absolute folders', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }], URI.file('/workspaces'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }], workspaceConfigPath);
assert.equal(actual.length, 3);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......@@ -97,7 +99,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple unique absolute folders with names', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }], URI.file('/workspaces'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }], workspaceConfigPath);
assert.equal(actual.length, 3);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......@@ -117,7 +119,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple unique absolute and relative folders', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/abc/test3', name: 'noName' }, { path: './test1' }], URI.file('src'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/abc/test3', name: 'noName' }, { path: './test1' }], workspaceConfigPath);
assert.equal(actual.length, 3);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......@@ -137,7 +139,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple absolute folders with duplicates', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }], URI.file('/workspaces'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }], workspaceConfigPath);
assert.equal(actual.length, 2);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......@@ -152,7 +154,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple absolute and relative folders with duplicates', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], URI.file('src'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], workspaceConfigPath);
assert.equal(actual.length, 3);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......@@ -172,7 +174,7 @@ suite('Workspace', () => {
});
test('toWorkspaceFolders with multiple absolute and relative folders with invalid paths', () => {
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], URI.file('src'));
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '', name: 'noName' }, { path: './test3' }, { path: '/abc/test1' }], workspaceConfigPath);
assert.equal(actual.length, 3);
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
......
......@@ -17,7 +17,7 @@ import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { Disposable } from 'vs/base/common/lifecycle';
import { originalFSPath, dirname as resourcesDirname, isEqualOrParent, joinPath } from 'vs/base/common/resources';
import { originalFSPath, isEqualOrParent, joinPath } from 'vs/base/common/resources';
export interface IStoredWorkspace {
folders: IStoredWorkspaceFolder[];
......@@ -71,7 +71,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
return {
id: workspaceIdentifier.id,
configPath: workspaceIdentifier.configPath,
folders: toWorkspaceFolders(workspace.folders, resourcesDirname(path)),
folders: toWorkspaceFolders(workspace.folders, workspaceIdentifier.configPath),
remoteAuthority: workspace.remoteAuthority
};
} catch (error) {
......
......@@ -24,7 +24,7 @@ suite('QueryBuilder', () => {
const PATTERN_INFO: IPatternInfo = { pattern: 'a' };
const ROOT_1 = fixPath('/foo/root1');
const ROOT_1_URI = getUri(ROOT_1);
const WS_FOLDER = getUri('/bar'); // location of the workspace file (not important except that it is a file URI)
const WS_CONFIG_PATH = getUri('/bar/test.code-workspace'); // location of the workspace file (not important except that it is a file URI)
let instantiationService: TestInstantiationService;
let queryBuilder: QueryBuilder;
......@@ -278,7 +278,7 @@ suite('QueryBuilder', () => {
const ROOT_2_URI = getUri(ROOT_2);
const ROOT_3 = fixPath('/project/root3');
const ROOT_3_URI = getUri(ROOT_3);
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: ROOT_2_URI.fsPath }, { path: ROOT_3_URI.fsPath }], WS_FOLDER);
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: ROOT_2_URI.fsPath }, { path: ROOT_3_URI.fsPath }], WS_CONFIG_PATH);
mockWorkspace.configuration = uri.file(fixPath('/config'));
mockConfigService.setUserConfiguration('search', {
......@@ -690,7 +690,7 @@ suite('QueryBuilder', () => {
test('relative includes w/two root folders', () => {
const ROOT_2 = '/project/root2';
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }], WS_FOLDER);
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }], WS_CONFIG_PATH);
mockWorkspace.configuration = uri.file(fixPath('config'));
const cases: [string, ISearchPathsInfo][] = [
......@@ -731,7 +731,7 @@ suite('QueryBuilder', () => {
test('include ./foldername', () => {
const ROOT_2 = '/project/root2';
const ROOT_1_FOLDERNAME = 'foldername';
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath, name: ROOT_1_FOLDERNAME }, { path: getUri(ROOT_2).fsPath }], WS_FOLDER);
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath, name: ROOT_1_FOLDERNAME }, { path: getUri(ROOT_2).fsPath }], WS_CONFIG_PATH);
mockWorkspace.configuration = uri.file(fixPath('config'));
const cases: [string, ISearchPathsInfo][] = [
......@@ -759,7 +759,7 @@ suite('QueryBuilder', () => {
test('relative includes w/multiple ambiguous root folders', () => {
const ROOT_2 = '/project/rootB';
const ROOT_3 = '/otherproject/rootB';
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }, { path: getUri(ROOT_3).fsPath }], WS_FOLDER);
mockWorkspace.folders = toWorkspaceFolders([{ path: ROOT_1_URI.fsPath }, { path: getUri(ROOT_2).fsPath }, { path: getUri(ROOT_3).fsPath }], WS_CONFIG_PATH);
mockWorkspace.configuration = uri.file(fixPath('/config'));
const cases: [string, ISearchPathsInfo][] = [
......
......@@ -181,8 +181,9 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
if (foldersToAdd.length) {
// Recompute current workspace folders if we have folders to add
const workspaceConfigFolder = dirname(this.getWorkspace().configuration!);
currentWorkspaceFolders = toWorkspaceFolders(newStoredFolders, workspaceConfigFolder);
const workspaceConfigPath = this.getWorkspace().configuration!;
const workspaceConfigFolder = dirname(workspaceConfigPath);
currentWorkspaceFolders = toWorkspaceFolders(newStoredFolders, workspaceConfigPath);
const currentWorkspaceFolderUris = currentWorkspaceFolders.map(folder => folder.uri);
const storedFoldersToAdd: IStoredWorkspaceFolder[] = [];
......@@ -329,7 +330,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
return this.workspaceConfiguration.load({ id: workspaceIdentifier.id, configPath: workspaceIdentifier.configPath })
.then(() => {
const workspaceConfigPath = workspaceIdentifier.configPath;
const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), dirname(workspaceConfigPath));
const workspaceFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), workspaceConfigPath);
const workspaceId = workspaceIdentifier.id;
const workspace = new Workspace(workspaceId, workspaceFolders, workspaceConfigPath);
if (this.workspaceConfiguration.loaded) {
......@@ -549,7 +550,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
private onWorkspaceConfigurationChanged(): Promise<void> {
if (this.workspace && this.workspace.configuration && this._configuration) {
const workspaceConfigurationChangeEvent = this._configuration.compareAndUpdateWorkspaceConfiguration(this.workspaceConfiguration.getConfiguration());
let configuredFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), dirname(this.workspace.configuration));
let configuredFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), this.workspace.configuration);
const changes = this.compareFolders(this.workspace.folders, configuredFolders);
if (changes.added.length || changes.removed.length || changes.changed.length) {
this.workspace.folders = configuredFolders;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册