mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 17:24:01 -05:00
Merge from vscode 05fc61ffb1aee9fd19173c32113daed079f9b7bd (#5074)
* Merge from vscode 05fc61ffb1aee9fd19173c32113daed079f9b7bd * fix tests
This commit is contained in:
@@ -4,14 +4,11 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { isAbsolute } from 'vs/base/common/path';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IWorkspaceIdentifier, IStoredWorkspaceFolder, isRawFileWorkspaceFolder, isRawUriWorkspaceFolder, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { coalesce, distinct } from 'vs/base/common/arrays';
|
||||
import { isLinux } from 'vs/base/common/platform';
|
||||
|
||||
export const IWorkspaceContextService = createDecorator<IWorkspaceContextService>('contextService');
|
||||
|
||||
@@ -225,17 +222,21 @@ export class WorkspaceFolder implements IWorkspaceFolder {
|
||||
}
|
||||
}
|
||||
|
||||
export function toWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo?: URI): WorkspaceFolder[] {
|
||||
let workspaceFolders = parseWorkspaceFolders(configuredFolders, relativeTo);
|
||||
return ensureUnique(coalesce(workspaceFolders))
|
||||
.map(({ uri, raw, name }, index) => new WorkspaceFolder({ uri, name: name || resources.basenameOrAuthority(uri), index }, raw));
|
||||
export function toWorkspaceFolder(resource: URI): WorkspaceFolder {
|
||||
return new WorkspaceFolder({ uri: resource, index: 0, name: resources.basenameOrAuthority(resource) }, { uri: resource.toString() });
|
||||
}
|
||||
|
||||
function parseWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], relativeTo: URI | undefined): Array<WorkspaceFolder | undefined> {
|
||||
return configuredFolders.map((configuredFolder, index) => {
|
||||
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)) {
|
||||
uri = toUri(configuredFolder.path, relativeTo);
|
||||
if (configuredFolder.path) {
|
||||
uri = resources.resolvePath(relativeTo, configuredFolder.path);
|
||||
}
|
||||
} else if (isRawUriWorkspaceFolder(configuredFolder)) {
|
||||
try {
|
||||
uri = URI.parse(configuredFolder.uri);
|
||||
@@ -248,25 +249,16 @@ function parseWorkspaceFolders(configuredFolders: IStoredWorkspaceFolder[], rela
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
if (!uri) {
|
||||
return undefined;
|
||||
}
|
||||
return new WorkspaceFolder({ uri, name: configuredFolder.name! /*is ensured in caller*/, index }, configuredFolder);
|
||||
});
|
||||
}
|
||||
if (uri) {
|
||||
// remove duplicates
|
||||
let comparisonKey = resources.getComparisonKey(uri);
|
||||
if (!seen[comparisonKey]) {
|
||||
seen[comparisonKey] = true;
|
||||
|
||||
function toUri(path: string, relativeTo: URI | undefined): URI | null {
|
||||
if (path) {
|
||||
if (isAbsolute(path)) {
|
||||
return URI.file(path);
|
||||
}
|
||||
if (relativeTo) {
|
||||
return resources.joinPath(relativeTo, path);
|
||||
const name = configuredFolder.name || resources.basenameOrAuthority(uri);
|
||||
result.push(new WorkspaceFolder({ uri, name, index: result.length }, configuredFolder));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function ensureUnique(folders: WorkspaceFolder[]): WorkspaceFolder[] {
|
||||
return distinct(folders, folder => isLinux ? folder.uri.toString() : folder.uri.toString().toLowerCase());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -4,15 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
|
||||
import { Workspace, toWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
const wsUri = URI.file(isWindows ? 'C:\\testWorkspace' : '/testWorkspace');
|
||||
export const TestWorkspace = testWorkspace(wsUri);
|
||||
|
||||
export function testWorkspace(resource: URI): Workspace {
|
||||
return new Workspace(
|
||||
resource.toString(),
|
||||
toWorkspaceFolders([{ path: resource.fsPath }])
|
||||
);
|
||||
return new Workspace(resource.toString(), [toWorkspaceFolder(resource)]);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,30 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import { Workspace, toWorkspaceFolders, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IRawFileWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
suite('Workspace', () => {
|
||||
|
||||
const fileFolder = isWindows ? 'c:\\src' : '/src';
|
||||
const abcFolder = isWindows ? 'c:\\abc' : '/abc';
|
||||
|
||||
const testFolderUri = URI.file(path.join(fileFolder, 'test'));
|
||||
const mainFolderUri = URI.file(path.join(fileFolder, 'main'));
|
||||
const test1FolderUri = URI.file(path.join(fileFolder, 'test1'));
|
||||
const test2FolderUri = URI.file(path.join(fileFolder, 'test2'));
|
||||
const test3FolderUri = URI.file(path.join(fileFolder, 'test3'));
|
||||
const abcTest1FolderUri = URI.file(path.join(abcFolder, 'test1'));
|
||||
const abcTest3FolderUri = URI.file(path.join(abcFolder, 'test3'));
|
||||
|
||||
const workspaceConfigUri = URI.file(path.join(fileFolder, '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 })]);
|
||||
const expected = new WorkspaceFolder({ uri: testFolderUri, name: '', index: 2 });
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: mainFolderUri, name: '', index: 0 }), expected, new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
|
||||
const actual = testObject.getFolder(expected.uri);
|
||||
|
||||
@@ -20,172 +35,172 @@ suite('Workspace', () => {
|
||||
});
|
||||
|
||||
test('getFolder returns the folder if the uri is sub', () => {
|
||||
const expected = new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 0 });
|
||||
let testObject = new Workspace('', [expected, new WorkspaceFolder({ uri: URI.file('/src/main'), name: '', index: 1 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
const expected = new WorkspaceFolder({ uri: testFolderUri, name: '', index: 0 });
|
||||
let testObject = new Workspace('', [expected, new WorkspaceFolder({ uri: mainFolderUri, name: '', index: 1 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 2 })]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/test/a'));
|
||||
const actual = testObject.getFolder(URI.file(path.join(fileFolder, 'test/a')));
|
||||
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('getFolder returns the closest folder if the uri is sub', () => {
|
||||
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 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 }), expected]);
|
||||
const expected = new WorkspaceFolder({ uri: testFolderUri, name: '', index: 2 });
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: mainFolderUri, name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 }), expected]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/test/a'));
|
||||
const actual = testObject.getFolder(URI.file(path.join(fileFolder, 'test/a')));
|
||||
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('getFolder returns null if the uri is not sub', () => {
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: URI.file('/src/test'), name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 })]);
|
||||
let testObject = new Workspace('', [new WorkspaceFolder({ uri: testFolderUri, name: '', index: 0 }), new WorkspaceFolder({ uri: URI.file('/src/code'), name: '', index: 1 })]);
|
||||
|
||||
const actual = testObject.getFolder(URI.file('/src/main/a'));
|
||||
const actual = testObject.getFolder(URI.file(path.join(fileFolder, 'main/a')));
|
||||
|
||||
assert.equal(actual, undefined);
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with single absolute folder', () => {
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test' }]);
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 1);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, testFolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test');
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with single relative folder', () => {
|
||||
const actual = toWorkspaceFolders([{ path: './test' }], URI.file('src'));
|
||||
const actual = toWorkspaceFolders([{ path: './test' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 1);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, testFolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, './test');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test');
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with single absolute folder with name', () => {
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }]);
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test', name: 'hello' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 1);
|
||||
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, testFolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'hello');
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with multiple unique absolute folders', () => {
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }]);
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3' }, { path: '/src/test1' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 3);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/src/test3').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, test3FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, '/src/test3');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'test3');
|
||||
|
||||
assert.equal(actual[2].uri.fsPath, URI.file('/src/test1').fsPath);
|
||||
assert.equal(actual[2].uri.fsPath, test1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[2].raw).path, '/src/test1');
|
||||
assert.equal(actual[2].index, 2);
|
||||
assert.equal(actual[2].name, 'test1');
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with multiple unique absolute folders with names', () => {
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }]);
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test3', name: 'noName' }, { path: '/src/test1' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 3);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/src/test3').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, test3FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, '/src/test3');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'noName');
|
||||
|
||||
assert.equal(actual[2].uri.fsPath, URI.file('/src/test1').fsPath);
|
||||
assert.equal(actual[2].uri.fsPath, test1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[2].raw).path, '/src/test1');
|
||||
assert.equal(actual[2].index, 2);
|
||||
assert.equal(actual[2].name, 'test1');
|
||||
});
|
||||
|
||||
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' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 3);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/abc/test3').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, abcTest3FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, '/abc/test3');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'noName');
|
||||
|
||||
assert.equal(actual[2].uri.fsPath, URI.file('/src/test1').fsPath);
|
||||
assert.equal(actual[2].uri.fsPath, test1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[2].raw).path, './test1');
|
||||
assert.equal(actual[2].index, 2);
|
||||
assert.equal(actual[2].name, 'test1');
|
||||
});
|
||||
|
||||
test('toWorkspaceFolders with multiple absolute folders with duplicates', () => {
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }]);
|
||||
const actual = toWorkspaceFolders([{ path: '/src/test2' }, { path: '/src/test2', name: 'noName' }, { path: '/src/test1' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 2);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/src/test1').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, test1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, '/src/test1');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'test1');
|
||||
});
|
||||
|
||||
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' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 3);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/src/test3').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, test3FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, '/src/test3');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'noName');
|
||||
|
||||
assert.equal(actual[2].uri.fsPath, URI.file('/abc/test1').fsPath);
|
||||
assert.equal(actual[2].uri.fsPath, abcTest1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[2].raw).path, '/abc/test1');
|
||||
assert.equal(actual[2].index, 2);
|
||||
assert.equal(actual[2].name, 'test1');
|
||||
});
|
||||
|
||||
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' }], workspaceConfigUri);
|
||||
|
||||
assert.equal(actual.length, 3);
|
||||
assert.equal(actual[0].uri.fsPath, URI.file('/src/test2').fsPath);
|
||||
assert.equal(actual[0].uri.fsPath, test2FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[0].raw).path, '/src/test2');
|
||||
assert.equal(actual[0].index, 0);
|
||||
assert.equal(actual[0].name, 'test2');
|
||||
|
||||
assert.equal(actual[1].uri.fsPath, URI.file('/src/test3').fsPath);
|
||||
assert.equal(actual[1].uri.fsPath, test3FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[1].raw).path, './test3');
|
||||
assert.equal(actual[1].index, 1);
|
||||
assert.equal(actual[1].name, 'test3');
|
||||
|
||||
assert.equal(actual[2].uri.fsPath, URI.file('/abc/test1').fsPath);
|
||||
assert.equal(actual[2].uri.fsPath, abcTest1FolderUri.fsPath);
|
||||
assert.equal((<IRawFileWorkspaceFolder>actual[2].raw).path, '/abc/test1');
|
||||
assert.equal(actual[2].index, 2);
|
||||
assert.equal(actual[2].name, 'test1');
|
||||
|
||||
Reference in New Issue
Block a user