提交 919d3fec 编写于 作者: J Johannes Rieken

make getPath return undefined when there is not just one root, #28526

上级 88230f5d
......@@ -43,7 +43,16 @@ export class ExtHostWorkspace extends ExtHostWorkspaceShape {
// this is legacy from the days before having
// multi-root and we keep it only alive if there
// is just one workspace folder.
return this._workspace ? this._workspace.roots[0].fsPath : undefined;
if (!this._workspace) {
return undefined;
}
const { roots } = this._workspace;
if (roots.length === 1) {
return roots[0].fsPath;
}
// return `undefined` when there no or more than 1
// root folder.
return undefined;
}
getRelativePath(pathOrUri: string | vscode.Uri): string {
......
......@@ -48,4 +48,21 @@ suite('ExtHostWorkspace', function () {
assert.equal(ws.getRelativePath('/Coding/Two/files/out.txt'), 'files/out.txt');
assert.equal(ws.getRelativePath('/Coding/Two2/files/out.txt'), '/Coding/Two2/files/out.txt');
});
test('getPath, legacy', function () {
let ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [] });
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), null);
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), undefined);
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [URI.file('Folder'), URI.file('Another/Folder')] });
assert.equal(ws.getPath(), undefined);
ws = new ExtHostWorkspace(new TestThreadService(), { id: 'foo', name: 'Test', roots: [URI.file('/Folder')] });
assert.equal(ws.getPath(), '/Folder');
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册