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

Keep identity with relative paths, fixes #2549

上级 8c94e89e
......@@ -168,6 +168,8 @@ export default class URI {
path = path.replace(/%/g, '%25');
path = path.replace(/#/g, '%23');
path = path.replace(/\?/g, '%3F');
// makes sure something like 'C:/Users' isn't
// parsed as scheme='C', path='Users'
path = URI._driveLetter.test(path)
? '/' + path
: path;
......@@ -178,7 +180,7 @@ export default class URI {
}
ret = ret.with('file', undefined,
decodeURIComponent(ret.path),
decodeURIComponent(ret.path[0] === '/' ? ret.path : '/' + ret.path), // path starts with slash
undefined, undefined);
return ret;
......
......@@ -24,7 +24,7 @@ suite('URI', () => {
assert.equal(URI.file('c:/win/path/').fsPath.replace(/\\/g, '/'), 'c:/win/path/');
assert.equal(URI.file('C:/win/path').fsPath.replace(/\\/g, '/'), 'c:/win/path');
assert.equal(URI.file('/c:/win/path').fsPath.replace(/\\/g, '/'), 'c:/win/path');
assert.equal(URI.file('./c/win/path').fsPath.replace(/\\/g, '/'), './c/win/path');
assert.equal(URI.file('./c/win/path').fsPath.replace(/\\/g, '/'), '/./c/win/path');
assert.equal(URI.file('c:\\win\\path').fsPath.replace(/\\/g, '/'), 'c:/win/path');
assert.equal(URI.file('c:\\win/path').fsPath.replace(/\\/g, '/'), 'c:/win/path');
});
......@@ -276,6 +276,21 @@ suite('URI', () => {
assert.equal(value.toString(), 'file:///c%3A/test/drive');
});
test('URI#file, always slash', () => {
var value = URI.file('a.file');
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/a.file');
assert.equal(value.toString(), 'file:///a.file');
value = URI.parse(value.toString());
assert.equal(value.scheme, 'file');
assert.equal(value.authority, '');
assert.equal(value.path, '/a.file');
assert.equal(value.toString(), 'file:///a.file');
});
test('URI#file, disallow scheme', () => {
assert.throws(() => URI.file('file:///some/path'));
});
......
......@@ -229,11 +229,11 @@ suite('TS - Project Resolver', () => {
};
var files: { [n: string]: string } = Object.create(null);
files['jsconfig.json'] = '{}';
files['a.js'] = 'a';
files['b.js'] = 'b';
files['c.d.ts'] = 'c';
files['d.ts'] = 'd';
files['/jsconfig.json'] = '{}';
files['/a.js'] = 'a';
files['/b.js'] = 'b';
files['/c.d.ts'] = 'c';
files['/d.ts'] = 'd';
var resolver = instantiationService.createChild({
searchService: createSearchService(files),
......
......@@ -289,15 +289,15 @@ suite('ExtHostTypes', function() {
edit.set(a, [types.TextEdit.insert(new types.Position(0, 0), 'fff')]);
assert.ok(edit.has(a));
assert.equal(edit.size, 1);
assertToJSON(edit, [['file://a.ts', [{ range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: 'fff' }]]]);
assertToJSON(edit, [['file:///a.ts', [{ range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: 'fff' }]]]);
edit.insert(b, new types.Position(1, 1), 'fff');
edit.delete(b, new types.Range(0, 0, 0, 0));
assert.ok(edit.has(b));
assert.equal(edit.size, 2);
assertToJSON(edit, [
['file://a.ts', [{ range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: 'fff' }]],
['file://b.ts', [{ range: [{ line: 1, character: 1 }, { line: 1, character: 1 }], newText: 'fff' }, { range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: '' }]]
['file:///a.ts', [{ range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: 'fff' }]],
['file:///b.ts', [{ range: [{ line: 1, character: 1 }, { line: 1, character: 1 }], newText: 'fff' }, { range: [{ line: 0, character: 0 }, { line: 0, character: 0 }], newText: '' }]]
]);
edit.set(b, undefined);
......@@ -313,8 +313,8 @@ suite('ExtHostTypes', function() {
assertToJSON(new types.Selection(3, 4, 2, 1), { start: { line: 2, character: 1 }, end: { line: 3, character: 4 }, anchor: { line: 3, character: 4 }, active: { line: 2, character: 1 } });
assertToJSON(new types.Location(types.Uri.file('u.ts'), new types.Range(1, 2, 3, 4)), { uri: 'file://u.ts', range: [{ line: 1, character: 2 }, { line: 3, character: 4 }] });
assertToJSON(new types.Location(types.Uri.file('u.ts'), new types.Position(3, 4)), { uri: 'file://u.ts', range: [{ line: 3, character: 4 }, { line: 3, character: 4 }] });
assertToJSON(new types.Location(types.Uri.file('u.ts'), new types.Range(1, 2, 3, 4)), { uri: 'file:///u.ts', range: [{ line: 1, character: 2 }, { line: 3, character: 4 }] });
assertToJSON(new types.Location(types.Uri.file('u.ts'), new types.Position(3, 4)), { uri: 'file:///u.ts', range: [{ line: 3, character: 4 }, { line: 3, character: 4 }] });
let diag = new types.Diagnostic(new types.Range(0, 1, 2, 3), 'hello');
assertToJSON(diag, { severity: 'Error', message: 'hello', range: [{ line: 0, character: 1 }, { line: 2, character: 3 }] });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册