diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index 180556989..084229775 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -26,7 +26,7 @@ export interface TestContext { * @param createService A factory that creates the TypeScript service. Allows to test subclasses of TypeScriptService * @param files A Map from URI to file content of files that should be available in the workspace */ -export const initializeTypeScriptService = (createService: TypeScriptServiceFactory, files: Map) => async function (this: TestContext): Promise { +export const initializeTypeScriptService = (createService: TypeScriptServiceFactory, rootUri: string, files: Map) => async function (this: TestContext): Promise { this.service = createService({ textDocumentXcontent(params: TextDocumentContentParams): Promise { if (!files.has(params.textDocument.uri)) { @@ -54,7 +54,7 @@ export const initializeTypeScriptService = (createService: TypeScriptServiceFact }); await this.service.initialize({ processId: process.pid, - rootUri: 'file:///', + rootUri, capabilities: { xcontentProvider: true, xfilesProvider: true @@ -74,23 +74,23 @@ export async function shutdownTypeScriptService(this: TestContext): Promise'], - ['file:///src/dir/index.ts', 'import * as m from "dep";'] + [rootUri + 'src/tsd.d.ts', '/// '], + [rootUri + 'src/dir/index.ts', 'import * as m from "dep";'] ])) as any); afterEach(shutdownService as any); @@ -336,7 +336,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('with tsd.d.ts', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///src/dir/index.ts' + uri: rootUri + 'src/dir/index.ts' }, position: { line: 0, @@ -344,7 +344,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///typings/dep.d.ts', + uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, @@ -361,7 +361,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('on import alias', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///src/a.ts' + uri: rootUri + 'src/a.ts' }, position: { line: 0, @@ -369,7 +369,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///typings/dep.d.ts', + uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, @@ -385,7 +385,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('on module name', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///src/a.ts' + uri: rootUri + 'src/a.ts' }, position: { line: 0, @@ -393,7 +393,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///typings/dep.d.ts', + uri: rootUri + 'typings/dep.d.ts', range: { start: { line: 0, @@ -411,8 +411,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('DefinitelyTyped', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///package.json', JSON.stringify({ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'package.json', JSON.stringify({ private: true, name: 'definitely-typed', version: '0.0.1', @@ -439,14 +439,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'types-publisher': 'Microsoft/types-publisher#production' } }, null, 4)], - ['file:///types/resolve/index.d.ts', [ + [rootUri + 'types/resolve/index.d.ts', [ '/// ', '', 'type resolveCallback = (err: Error, resolved?: string) => void;', 'declare function resolve(id: string, cb: resolveCallback): void;', '' ].join('\n')], - ['file:///types/resolve/tsconfig.json', JSON.stringify({ + [rootUri + 'types/resolve/tsconfig.json', JSON.stringify({ compilerOptions: { module: 'commonjs', lib: [ @@ -467,14 +467,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'index.d.ts' ] })], - ['file:///types/notResolve/index.d.ts', [ + [rootUri + 'types/notResolve/index.d.ts', [ '/// ', '', 'type resolveCallback = (err: Error, resolved?: string) => void;', 'declare function resolve(id: string, cb: resolveCallback): void;', '' ].join('\n')], - ['file:///types/notResolve/tsconfig.json', JSON.stringify({ + [rootUri + 'types/notResolve/tsconfig.json', JSON.stringify({ compilerOptions: { module: 'commonjs', lib: [ @@ -518,7 +518,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 2 } }, - uri: 'file:///types/resolve/index.d.ts' + uri: rootUri + 'types/resolve/index.d.ts' }, name: 'resolveCallback' }]); @@ -541,7 +541,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 2 } }, - uri: 'file:///types/resolve/index.d.ts' + uri: rootUri + 'types/resolve/index.d.ts' }, name: 'resolveCallback' }]); @@ -551,12 +551,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Workspace with root package.json', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', 'class a { foo() { const i = 1;} }'], - ['file:///foo/b.ts', 'class b { bar: number; baz(): number { return this.bar;}}; function qux() {}'], - ['file:///c.ts', 'import { x } from "dep/dep";'], - ['file:///package.json', '{ "name": "mypkg" }'], - ['file:///node_modules/dep/dep.ts', 'export var x = 1;'] + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', 'class a { foo() { const i = 1;} }'], + [rootUri + 'foo/b.ts', 'class b { bar: number; baz(): number { return this.bar;}}; function qux() {}'], + [rootUri + 'c.ts', 'import { x } from "dep/dep";'], + [rootUri + 'package.json', '{ "name": "mypkg" }'], + [rootUri + 'node_modules/dep/dep.ts', 'export var x = 1;'] ])) as any); afterEach(shutdownService as any); @@ -586,7 +586,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, name: 'a' }]); @@ -609,7 +609,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, name: 'a' }]); @@ -633,7 +633,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, name: 'a' }]); @@ -667,7 +667,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, name: 'a' }]); @@ -679,7 +679,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'a', kind: SymbolKind.Class, location: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', range: { start: { line: 0, @@ -696,7 +696,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'foo', kind: SymbolKind.Method, location: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', range: { start: { line: 0, @@ -714,7 +714,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'i', kind: SymbolKind.Constant, location: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', range: { start: { line: 0, @@ -732,7 +732,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'x', kind: SymbolKind.Variable, location: { - uri: 'file:///c.ts', + uri: rootUri + 'c.ts', range: { start: { line: 0, @@ -749,7 +749,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'b', kind: SymbolKind.Class, location: { - uri: 'file:///foo/b.ts', + uri: rootUri + 'foo/b.ts', range: { start: { line: 0, @@ -766,7 +766,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'bar', kind: SymbolKind.Property, location: { - uri: 'file:///foo/b.ts', + uri: rootUri + 'foo/b.ts', range: { start: { line: 0, @@ -784,7 +784,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'baz', kind: SymbolKind.Method, location: { - uri: 'file:///foo/b.ts', + uri: rootUri + 'foo/b.ts', range: { start: { line: 0, @@ -802,7 +802,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'qux', kind: SymbolKind.Function, location: { - uri: 'file:///foo/b.ts', + uri: rootUri + 'foo/b.ts', range: { start: { line: 0, @@ -824,7 +824,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor name: 'a', kind: SymbolKind.Class, location: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', range: { start: { line: 0, @@ -863,7 +863,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }]); } as any); @@ -887,7 +887,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }]); } as any); @@ -909,7 +909,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///c.ts' + uri: rootUri + 'c.ts' }, symbol: { containerKind: '', @@ -940,7 +940,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }, { @@ -961,7 +961,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }, { @@ -982,7 +982,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }, { @@ -997,7 +997,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///c.ts' + uri: rootUri + 'c.ts' }, symbol: { containerKind: '', @@ -1024,7 +1024,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///foo/b.ts' + uri: rootUri + 'foo/b.ts' } }, { @@ -1045,7 +1045,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///foo/b.ts' + uri: rootUri + 'foo/b.ts' } }, { @@ -1066,7 +1066,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///foo/b.ts' + uri: rootUri + 'foo/b.ts' } }, { @@ -1087,7 +1087,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///foo/b.ts' + uri: rootUri + 'foo/b.ts' } }, { @@ -1108,7 +1108,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 0 } }, - uri: 'file:///foo/b.ts' + uri: rootUri + 'foo/b.ts' } } ]); @@ -1118,8 +1118,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Dependency detection', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///package.json', JSON.stringify({ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'package.json', JSON.stringify({ name: 'tslint', version: '4.0.2', dependencies: { @@ -1138,13 +1138,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor typescript: '>=2.0.0' } })], - ['file:///node_modules/dep/package.json', JSON.stringify({ + [rootUri + 'node_modules/dep/package.json', JSON.stringify({ name: 'foo', dependencies: { shouldnotinclude: '0.0.0' } })], - ['file:///subproject/package.json', JSON.stringify({ + [rootUri + 'subproject/package.json', JSON.stringify({ name: 'subproject', repository: { url: 'https://github.com/my/subproject' @@ -1209,8 +1209,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('TypeScript library', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', 'let parameters = [];'] + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', 'let parameters = [];'] ])) as any); afterEach(shutdownService as any); @@ -1218,7 +1218,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor specify('type of parameters should be any[]', async function (this: TestContext) { const result = await this.service.textDocumentHover({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1246,8 +1246,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Live updates', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', 'let parameters = [];'] + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', 'let parameters = [];'] ])) as any); afterEach(shutdownService as any); @@ -1256,7 +1256,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1277,7 +1277,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidChange({ textDocument: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', version: 1 }, contentChanges: [{ @@ -1298,7 +1298,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1319,7 +1319,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidClose({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }); @@ -1336,7 +1336,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor const hoverParams = { textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1365,7 +1365,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidOpen({ textDocument: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', languageId: 'typescript', version: 1, text: 'let parameters: string[]' @@ -1382,7 +1382,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidChange({ textDocument: { - uri: 'file:///a.ts', + uri: rootUri + 'a.ts', version: 2 }, contentChanges: [{ @@ -1400,7 +1400,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor await this.service.textDocumentDidClose({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' } }); @@ -1415,19 +1415,19 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('References and imports', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', '/// \nnamespace qux {let f : foo;}'], - ['file:///b.ts', '/// '], - ['file:///c.ts', 'import * as d from "./foo/d"\nd.bar()'], - ['file:///foo/c.ts', 'namespace qux {export interface foo {}}'], - ['file:///foo/d.ts', 'export function bar() {}'], - ['file:///deeprefs/a.ts', '/// \nnamespace qux {\nlet f : foo;\n}'], - ['file:///deeprefs/b.ts', '/// '], - ['file:///deeprefs/c.ts', '/// '], - ['file:///deeprefs/d.ts', '/// '], - ['file:///deeprefs/e.ts', 'namespace qux {\nexport interface foo {}\n}'], - ['file:///missing/a.ts', '/// \n/// \nnamespace t {\n function foo() : Bar {\n return null;\n }\n}'], - ['file:///missing/b.ts', 'namespace t {\n export interface Bar {\n id?: number;\n }}'] + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', '/// \nnamespace qux {let f : foo;}'], + [rootUri + 'b.ts', '/// '], + [rootUri + 'c.ts', 'import * as d from "./foo/d"\nd.bar()'], + [rootUri + 'foo/c.ts', 'namespace qux {export interface foo {}}'], + [rootUri + 'foo/d.ts', 'export function bar() {}'], + [rootUri + 'deeprefs/a.ts', '/// \nnamespace qux {\nlet f : foo;\n}'], + [rootUri + 'deeprefs/b.ts', '/// '], + [rootUri + 'deeprefs/c.ts', '/// '], + [rootUri + 'deeprefs/d.ts', '/// '], + [rootUri + 'deeprefs/e.ts', 'namespace qux {\nexport interface foo {}\n}'], + [rootUri + 'missing/a.ts', '/// \n/// \nnamespace t {\n function foo() : Bar {\n return null;\n }\n}'], + [rootUri + 'missing/b.ts', 'namespace t {\n export interface Bar {\n id?: number;\n }}'] ])) as any); afterEach(shutdownService as any); @@ -1436,7 +1436,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve symbol imported with tripe-slash reference', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 1, @@ -1452,7 +1452,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor // omission. (It would probably show up in the // definition response if the user has already // navigated to deeprefs/e.ts.) - uri: 'file:///foo/c.ts', + uri: rootUri + 'foo/c.ts', range: { start: { line: 0, @@ -1468,7 +1468,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve symbol imported with import statement', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///c.ts' + uri: rootUri + 'c.ts' }, position: { line: 1, @@ -1476,7 +1476,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///foo/d.ts', + uri: rootUri + 'foo/d.ts', range: { start: { line: 0, @@ -1492,7 +1492,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve definition with missing reference', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///missing/a.ts' + uri: rootUri + 'missing/a.ts' }, position: { line: 3, @@ -1500,7 +1500,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///missing/b.ts', + uri: rootUri + 'missing/b.ts', range: { start: { line: 1, @@ -1519,7 +1519,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor // This test will fail once we'll increase (or remove) depth limit const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///deeprefs/a.ts' + uri: rootUri + 'deeprefs/a.ts' }, position: { line: 2, @@ -1527,7 +1527,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } }); assert.deepEqual(result, [{ - uri: 'file:///deeprefs/e.ts', + uri: rootUri + 'deeprefs/e.ts', range: { start: { line: 1, @@ -1544,13 +1544,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('TypeScript libraries', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///tsconfig.json', JSON.stringify({ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'tsconfig.json', JSON.stringify({ compilerOptions: { lib: ['es2016', 'dom'] } })], - ['file:///a.ts', 'function foo(n: Node): {console.log(n.parentNode, NaN})}'] + [rootUri + 'a.ts', 'function foo(n: Node): {console.log(n.parentNode, NaN})}'] ])) as any); afterEach(shutdownService as any); @@ -1559,7 +1559,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should load local library file', async function (this: TestContext) { const result = await this.service.textDocumentHover({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1610,7 +1610,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should resolve TS libraries to github URL', async function (this: TestContext) { assert.deepEqual(await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1644,7 +1644,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor assert.deepEqual(await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1668,8 +1668,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('textDocumentReferences()', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', [ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', [ 'class A {', ' /** foo doc*/', ' foo() {}', @@ -1687,15 +1687,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'const a = new A();', 'a.baz(32, sd)' ].join('\n')], - ['file:///uses-import.ts', [ + [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', 'i.d()' ].join('\n')], - ['file:///also-uses-import.ts', [ + [rootUri + 'also-uses-import.ts', [ 'import {d} from "./import"', 'd()' ].join('\n')], - ['file:///import.ts', '/** d doc*/ export function d() {}'] + [rootUri + 'import.ts', '/** d doc*/ export function d() {}'] ])) as any); afterEach(shutdownService as any); @@ -1703,7 +1703,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide an empty response when no reference is found', async function (this: TestContext) { const result = await this.service.textDocumentReferences({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1717,7 +1717,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should include the declaration if requested', async function (this: TestContext) { const result = await this.service.textDocumentReferences({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 4, @@ -1736,14 +1736,14 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 4 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }]); } as any); it('should provide a reference within the same file', async function (this: TestContext) { const result = await this.service.textDocumentReferences({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 10, @@ -1762,13 +1762,13 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 15 } }, - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }]); } as any); it('should provide two references from imports', async function (this: TestContext) { const result = await this.service.textDocumentReferences({ textDocument: { - uri: 'file:///import.ts' + uri: rootUri + 'import.ts' }, position: { line: 0, @@ -1788,7 +1788,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 1 } }, - uri: 'file:///uses-import.ts' + uri: rootUri + 'uses-import.ts' }, { range: { @@ -1801,15 +1801,15 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor line: 1 } }, - uri: 'file:///also-uses-import.ts' + uri: rootUri + 'also-uses-import.ts' } ]); } as any); } as any); describe('textDocumentSignatureHelp()', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', [ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', [ 'class A {', ' /** foo doc*/', ' foo() {}', @@ -1827,22 +1827,22 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'const a = new A();', 'a.baz(32, sd)' ].join('\n')], - ['file:///uses-import.ts', [ + [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', 'i.d()' ].join('\n')], - ['file:///import.ts', '/** d doc*/ export function d() {}'], - ['file:///uses-reference.ts', [ + [rootUri + 'import.ts', '/** d doc*/ export function d() {}'], + [rootUri + 'uses-reference.ts', [ '/// ', 'let z : foo.' ].join('\n')], - ['file:///reference.ts', [ + [rootUri + 'reference.ts', [ 'namespace foo {', ' /** bar doc*/', ' export interface bar {}', '}' ].join('\n')], - ['file:///empty.ts', ''] + [rootUri + 'empty.ts', ''] ])) as any); afterEach(shutdownService as any); @@ -1850,7 +1850,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide a valid empty response when no signature is found', async function (this: TestContext) { const result = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 0, @@ -1867,7 +1867,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide signature help with parameters in the same file', async function (this: TestContext) { const result = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 15, @@ -1896,7 +1896,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should provide signature help from imported symbols', async function (this: TestContext) { const result = await this.service.textDocumentSignatureHelp({ textDocument: { - uri: 'file:///uses-import.ts' + uri: rootUri + 'uses-import.ts' }, position: { line: 1, @@ -1917,8 +1917,8 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); describe('textDocumentCompletion()', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///a.ts', [ + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'a.ts', [ 'class A {', ' /** foo doc*/', ' foo() {}', @@ -1932,22 +1932,22 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor 'const a = new A();', 'a.' ].join('\n')], - ['file:///uses-import.ts', [ + [rootUri + 'uses-import.ts', [ 'import * as i from "./import"', 'i.' ].join('\n')], - ['file:///import.ts', '/** d doc*/ export function d() {}'], - ['file:///uses-reference.ts', [ + [rootUri + 'import.ts', '/** d doc*/ export function d() {}'], + [rootUri + 'uses-reference.ts', [ '/// ', 'let z : foo.' ].join('\n')], - ['file:///reference.ts', [ + [rootUri + 'reference.ts', [ 'namespace foo {', ' /** bar doc*/', ' export interface bar {}', '}' ].join('\n')], - ['file:///empty.ts', ''] + [rootUri + 'empty.ts', ''] ])) as any); afterEach(shutdownService as any); @@ -1955,7 +1955,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions in the same file', async function (this: TestContext) { const result = await this.service.textDocumentCompletion({ textDocument: { - uri: 'file:///a.ts' + uri: rootUri + 'a.ts' }, position: { line: 11, @@ -1997,7 +1997,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions for imported symbols', async function (this: TestContext) { const result = await this.service.textDocumentCompletion({ textDocument: { - uri: 'file:///uses-import.ts' + uri: rootUri + 'uses-import.ts' }, position: { line: 1, @@ -2018,7 +2018,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions for referenced symbols', async function (this: TestContext) { const result = await this.service.textDocumentCompletion({ textDocument: { - uri: 'file:///uses-reference.ts' + uri: rootUri + 'uses-reference.ts' }, position: { line: 1, @@ -2039,7 +2039,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('produces completions for empty files', async function (this: TestContext) { const result = await this.service.textDocumentCompletion({ textDocument: { - uri: 'file:///empty.ts' + uri: rootUri + 'empty.ts' }, position: { line: 0, @@ -2052,12 +2052,12 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor describe('Special file names', function (this: TestContext) { - beforeEach(initializeTypeScriptService(createService, new Map([ - ['file:///keywords-in-path/class/constructor/a.ts', 'export function a() {}'], - ['file:///special-characters-in-path/%40foo/b.ts', 'export function b() {}'], - ['file:///windows/app/master.ts', '/// \nc();'], - ['file:///windows/lib/master.ts', '/// '], - ['file:///windows/lib/slave.ts', 'function c() {}'] + beforeEach(initializeTypeScriptService(createService, rootUri, new Map([ + [rootUri + 'keywords-in-path/class/constructor/a.ts', 'export function a() {}'], + [rootUri + 'special-characters-in-path/%40foo/b.ts', 'export function b() {}'], + [rootUri + 'windows/app/master.ts', '/// \nc();'], + [rootUri + 'windows/lib/master.ts', '/// '], + [rootUri + 'windows/lib/slave.ts', 'function c() {}'] ])) as any); afterEach(shutdownService as any); @@ -2065,7 +2065,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should accept files with TypeScript keywords in path', async function (this: TestContext) { const result = await this.service.textDocumentHover({ textDocument: { - uri: 'file:///keywords-in-path/class/constructor/a.ts' + uri: rootUri + 'keywords-in-path/class/constructor/a.ts' }, position: { line: 0, @@ -2092,7 +2092,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should accept files with special characters in path', async function (this: TestContext) { const result = await this.service.textDocumentHover({ textDocument: { - uri: 'file:///special-characters-in-path/%40foo/b.ts' + uri: rootUri + 'special-characters-in-path/%40foo/b.ts' }, position: { line: 0, @@ -2119,7 +2119,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor it('should handle Windows-style paths in triple slash references', async function (this: TestContext) { const result = await this.service.textDocumentDefinition({ textDocument: { - uri: 'file:///windows/app/master.ts' + uri: rootUri + 'windows/app/master.ts' }, position: { line: 1, @@ -2137,7 +2137,7 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor character: 10 } }, - uri: 'file:///windows/lib/slave.ts' + uri: rootUri + 'windows/lib/slave.ts' }]); } as any); } as any); diff --git a/src/test/typescript-service.test.ts b/src/test/typescript-service.test.ts index 0fccc9595..d5d7161ea 100644 --- a/src/test/typescript-service.test.ts +++ b/src/test/typescript-service.test.ts @@ -3,5 +3,9 @@ import {TypeScriptService} from '../typescript-service'; import {describeTypeScriptService} from './typescript-service-helpers'; describe('TypeScriptService', () => { - describeTypeScriptService((client, options) => new TypeScriptService(client, options)); + for (const rootUri of ['file:///', 'file:///c:/foo/bar/', 'file:///foo/bar/']) { + describe(`rootUri ${rootUri}`, () => { + describeTypeScriptService((client, options) => new TypeScriptService(client, options), undefined, rootUri); + }); + } }); diff --git a/src/util.ts b/src/util.ts index d5cf9a5f6..9f08c677e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -90,7 +90,7 @@ export function path2uri(root: string, file: string): string { } else { p = file; } - p = toUnixPath(p).split('/').map(encodeURIComponent).join('/'); + p = toUnixPath(p).split('/').map((val, i) => i <= 1 && /^[a-z]:$/i.test(val) ? val : encodeURIComponent(val)).join('/'); return ret + p; }