From c0047fc35ae07f16eea9de919c99872de94055f2 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Wed, 12 Apr 2017 19:00:12 +0200 Subject: [PATCH 1/3] Add tests for textDocument/references Tests empty, one in-file and multiple imported references For #146 --- src/test/typescript-service-helpers.ts | 116 +++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index cec2fdd6c..5a472243a 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -1531,6 +1531,122 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor } as any); } as any); + describe('textDocumentReferences()', function (this: TestContext) { + beforeEach(initializeTypeScriptService(createService, new Map([ + ['file:///a.ts', [ + 'class A {', + ' /** foo doc*/', + ' foo() {}', + ' /** bar doc*/', + ' bar(): number { return 1; }', + ' /** ', + ' * The Baz function', + ' * @param num Number parameter', + ' * @param text Text parameter', + ' */', + ' baz(num: number, text: string): string { return ""; }', + ' /** qux doc*/', + ' qux: number;', + '}', + 'const a = new A();', + 'a.baz(32, sd)' + ].join('\n')], + ['file:///uses-import.ts', [ + 'import * as i from "./import"', + 'i.d()' + ].join('\n')], + ['file:///also-uses-import.ts', [ + 'import {d} from "./import"', + 'd()' + ].join('\n')], + ['file:///import.ts', '/** d doc*/ export function d() {}'] + ])) as any); + + afterEach(shutdownService as any); + + 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' + }, + position: { + line: 0, + character: 0 + }, + context: { includeDeclaration: false } + }); + assert.deepEqual(result, []); + } 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' + }, + position: { + line: 10, + character: 5 + }, + context: { includeDeclaration: false } + }); + assert.deepEqual(result, [ + { + range: { + end: { + character: 5, + line: 15 + }, + start: { + character: 2, + line: 15 + } + }, + uri: 'file:///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' + }, + position: { + line: 0, + character: 28 + }, + context: { includeDeclaration: false } + }); + assert.deepEqual(result, [ + { + range: { + end: { + character: 3, + line: 1 + }, + start: { + character: 2, + line: 1 + } + }, + uri: 'file:///uses-import.ts' + }, + { + range: { + end: { + character: 1, + line: 1 + }, + start: { + character: 0, + line: 1 + } + }, + uri: 'file:///also-uses-import.ts' + } + ]); + } as any); + } as any); + describe('textDocumentSignatureHelp()', function (this: TestContext) { beforeEach(initializeTypeScriptService(createService, new Map([ ['file:///a.ts', [ From ac7845299e898a3123e5b2ac03e736fad780a577 Mon Sep 17 00:00:00 2001 From: Tom van Ommeren Date: Wed, 12 Apr 2017 20:00:45 +0200 Subject: [PATCH 2/3] Add test for includeDeclaration Verifies a location is returned even when no references are found --- src/test/typescript-service-helpers.ts | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index 5a472243a..e8a3e34f5 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -1578,6 +1578,34 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor assert.deepEqual(result, []); } as any); + it('should include the declaration if requested', async function (this: TestContext) { + const result = await this.service.textDocumentReferences({ + textDocument: { + uri: 'file:///a.ts' + }, + position: { + line: 4, + character: 5 + }, + context: { includeDeclaration: true } + }); + assert.deepEqual(result, [ + { + range: { + end: { + character: 7, + line: 4 + }, + start: { + character: 4, + line: 4 + } + }, + uri: 'file:///a.ts' + } + ]); + } as any); + it('should provide a reference within the same file', async function (this: TestContext) { const result = await this.service.textDocumentReferences({ textDocument: { From b735f0fc8b63b0380c2440e32c2469a75dcc26d4 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Wed, 12 Apr 2017 20:08:56 +0200 Subject: [PATCH 3/3] Fix indentation --- src/test/typescript-service-helpers.ts | 52 ++++++++++++-------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/test/typescript-service-helpers.ts b/src/test/typescript-service-helpers.ts index e8a3e34f5..e7c8fb18c 100644 --- a/src/test/typescript-service-helpers.ts +++ b/src/test/typescript-service-helpers.ts @@ -1589,21 +1589,19 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor }, context: { includeDeclaration: true } }); - assert.deepEqual(result, [ - { - range: { - end: { - character: 7, - line: 4 - }, - start: { - character: 4, - line: 4 - } + assert.deepEqual(result, [{ + range: { + end: { + character: 7, + line: 4 }, - uri: 'file:///a.ts' - } - ]); + start: { + character: 4, + line: 4 + } + }, + uri: 'file:///a.ts' + }]); } as any); it('should provide a reference within the same file', async function (this: TestContext) { @@ -1617,21 +1615,19 @@ export function describeTypeScriptService(createService: TypeScriptServiceFactor }, context: { includeDeclaration: false } }); - assert.deepEqual(result, [ - { - range: { - end: { - character: 5, - line: 15 - }, - start: { - character: 2, - line: 15 - } + assert.deepEqual(result, [{ + range: { + end: { + character: 5, + line: 15 }, - uri: 'file:///a.ts' - } - ]); + start: { + character: 2, + line: 15 + } + }, + uri: 'file:///a.ts' + }]); } as any); it('should provide two references from imports', async function (this: TestContext) { const result = await this.service.textDocumentReferences({