提交 a0d33217 编写于 作者: J Johannes Rieken

use path primitives when compute workspace relative path, fixes #10446

上级 a1c1d224
......@@ -13,6 +13,7 @@ suite('Paths', () => {
assert.equal(paths.relative('/test/api/files/test', '/test/api/files/lib/foo'), '../lib/foo');
assert.equal(paths.relative('far/boo', 'boo/far'), '../../boo/far');
assert.equal(paths.relative('far/boo', 'far/boo'), '');
assert.equal(paths.relative('far/boo', 'far/boo/bar/foo'), 'bar/foo');
});
test('dirname', () => {
......
......@@ -5,6 +5,7 @@
'use strict';
import URI from 'vs/base/common/uri';
import {relative, isEqualOrParent} from 'vs/base/common/paths';
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
import {IResourceEdit} from 'vs/editor/common/services/bulkEdit';
import {TPromise} from 'vs/base/common/winjs.base';
......@@ -28,7 +29,7 @@ export class ExtHostWorkspace {
return this._workspacePath;
}
getRelativePath(pathOrUri: string|Uri): string {
getRelativePath(pathOrUri: string | Uri): string {
let path: string;
if (typeof pathOrUri === 'string') {
......@@ -37,9 +38,8 @@ export class ExtHostWorkspace {
path = pathOrUri.fsPath;
}
if (this._workspacePath && this._workspacePath.length < path.length) {
// return relative(workspacePath, path);
return path.substring(this._workspacePath.length);
if (isEqualOrParent(path, this._workspacePath)) {
return relative(this._workspacePath, path);
}
return path;
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import {ExtHostWorkspace} from 'vs/workbench/api/node/extHostWorkspace';
import {TestThreadService} from './testThreadService';
suite('ExtHostWorkspace', function () {
test('asRelativePath', function () {
const ws = new ExtHostWorkspace(new TestThreadService(), 'm:/Coding/Applications/NewsWoWBot');
assert.equal(ws.getRelativePath('m:/Coding/Applications/NewsWoWBot/bernd/das/brot'), 'bernd/das/brot');
assert.equal(ws.getRelativePath('m:/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart'),
'm:/Apps/DartPubCache/hosted/pub.dartlang.org/convert-2.0.1/lib/src/hex.dart');
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册