Skip to content

Commit 16c3255

Browse files
author
Armando Aguirre
committed
Updated an incredible amount of tests.
1 parent 8004fec commit 16c3255

76 files changed

Lines changed: 184 additions & 139 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/harness/fourslash.ts

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,23 @@ namespace FourSlash {
584584

585585
public verifyGoToDefinition(arg0: any, endMarkerNames?: string | string[]) {
586586
this.verifyGoToX(arg0, endMarkerNames, () => this.getGoToDefinition());
587+
this.verifyGoToX(arg0, endMarkerNames, () => this.getGoToDefinitionAndBoundSpan());
587588
}
588589

589590
private getGoToDefinition(): ts.DefinitionInfo[] {
590591
return this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
591592
}
592593

594+
private getGoToDefinitionAndBoundSpan(): ts.DefinitionInfoAndBoundSpan {
595+
return this.languageService.getDefinitionAndBoundSpan(this.activeFile.fileName, this.currentCaretPosition);
596+
}
597+
593598
public verifyGoToType(arg0: any, endMarkerNames?: string | string[]) {
594599
this.verifyGoToX(arg0, endMarkerNames, () =>
595600
this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition));
596601
}
597602

598-
private verifyGoToX(arg0: any, endMarkerNames: string | string[] | undefined, getDefs: () => ts.DefinitionInfo[] | undefined) {
603+
private verifyGoToX(arg0: any, endMarkerNames: string | string[] | undefined, getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
599604
if (endMarkerNames) {
600605
this.verifyGoToXPlain(arg0, endMarkerNames, getDefs);
601606
}
@@ -615,7 +620,7 @@ namespace FourSlash {
615620
}
616621
}
617622

618-
private verifyGoToXPlain(startMarkerNames: string | string[], endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
623+
private verifyGoToXPlain(startMarkerNames: string | string[], endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
619624
for (const start of toArray(startMarkerNames)) {
620625
this.verifyGoToXSingle(start, endMarkerNames, getDefs);
621626
}
@@ -627,26 +632,60 @@ namespace FourSlash {
627632
}
628633
}
629634

630-
private verifyGoToXSingle(startMarkerName: string, endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
635+
private verifyGoToXSingle(startMarkerName: string, endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined) {
631636
this.goToMarker(startMarkerName);
632-
this.verifyGoToXWorker(toArray(endMarkerNames), getDefs);
637+
this.verifyGoToXWorker(toArray(endMarkerNames), getDefs, startMarkerName);
633638
}
634639

635-
private verifyGoToXWorker(endMarkers: string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
636-
const definitions = getDefs() || [];
640+
private verifyGoToXWorker(endMarkers: string[], getDefs: () => ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined, startMarkerName?: string) {
641+
const defs = getDefs();
642+
let definitions: ts.DefinitionInfo[] | ReadonlyArray<ts.DefinitionInfo>;
643+
let testName: string;
644+
if (this.isDefinitionInfoAndBoundSpan(defs)) {
645+
this.verifyDefinitionTextSpan(defs, startMarkerName);
646+
647+
definitions = defs.definitions;
648+
testName = "goToDefinitionsAndBoundSpan";
649+
}
650+
else {
651+
definitions = defs || [];
652+
testName = "goToDefinitions";
653+
}
637654

638655
if (endMarkers.length !== definitions.length) {
639-
this.raiseError(`goToDefinitions failed - expected to find ${endMarkers.length} definitions but got ${definitions.length}`);
656+
this.raiseError(`${testName} failed - expected to find ${endMarkers.length} definitions but got ${definitions.length}`);
640657
}
641658

642659
ts.zipWith(endMarkers, definitions, (endMarker, definition, i) => {
643660
const marker = this.getMarkerByName(endMarker);
644661
if (marker.fileName !== definition.fileName || marker.position !== definition.textSpan.start) {
645-
this.raiseError(`goToDefinition failed for definition ${endMarker} (${i}): expected ${marker.fileName} at ${marker.position}, got ${definition.fileName} at ${definition.textSpan.start}`);
662+
this.raiseError(`${testName} failed for definition ${endMarker} (${i}): expected ${marker.fileName} at ${marker.position}, got ${definition.fileName} at ${definition.textSpan.start}`);
646663
}
647664
});
648665
}
649666

667+
private verifyDefinitionTextSpan(defs: ts.DefinitionInfoAndBoundSpan, startMarkerName: string) {
668+
const range = this.testData.ranges.find(range => this.markerName(range.marker) === startMarkerName);
669+
670+
if (!range && !defs.textSpan) {
671+
return;
672+
}
673+
674+
if (!range) {
675+
this.raiseError(`goToDefinitionsAndBoundSpan failed - found a TextSpan ${JSON.stringify(defs.textSpan)} when it wasn't expected.`);
676+
}
677+
else if (defs.textSpan.start !== range.start || defs.textSpan.length !== range.end - range.start) {
678+
const expected: ts.TextSpan = {
679+
start: range.start, length: range.end - range.start
680+
};
681+
this.raiseError(`goToDefinitionsAndBoundSpan failed - expected to find TextSpan ${JSON.stringify(expected)} but got ${JSON.stringify(defs.textSpan)}`);
682+
}
683+
}
684+
685+
private isDefinitionInfoAndBoundSpan(definition: ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined): definition is ts.DefinitionInfoAndBoundSpan {
686+
return definition && (<ts.DefinitionInfoAndBoundSpan>definition).definitions !== undefined;
687+
}
688+
650689
public verifyGetEmitOutputForCurrentFile(expected: string): void {
651690
const emit = this.languageService.getEmitOutput(this.activeFile.fileName);
652691
if (emit.outputFiles.length !== 1) {
@@ -3828,6 +3867,7 @@ namespace FourSlashInterface {
38283867
}
38293868

38303869
public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[]): void;
3870+
public goToDefinition(startMarkerName: string | string[], endMarkerName: string | string[], range: FourSlash.Range): void;
38313871
public goToDefinition(startsAndEnds: [string | string[], string | string[]][]): void;
38323872
public goToDefinition(startsAndEnds: { [startMarkerName: string]: string | string[] }): void;
38333873
public goToDefinition(arg0: any, endMarkerName?: string | string[]) {

src/services/goToDefinition.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ namespace ts.GoToDefinition {
157157
}
158158

159159
// TODO: Add textSpan for triple slash references (file and type).
160+
const comment = findReferenceInPosition(sourceFile.referencedFiles, position);
161+
if (comment && tryResolveScriptReference(program, sourceFile, comment) || findReferenceInPosition(sourceFile.typeReferenceDirectives, position)) {
162+
return { definitions, textSpan: undefined };
163+
}
160164

161165
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
162166
const textSpan = createTextSpan(node.getStart(), node.getWidth());

tests/cases/fourslash/ambientShorthandGotoDefinition.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
// @Filename: user.ts
77
///////<reference path="declarations.d.ts"/>
8-
////import /*importFoo*/foo, {bar} from "jquery";
9-
////import * as /*importBaz*/baz from "jquery";
10-
////import /*importBang*/bang = require("jquery");
11-
////foo/*useFoo*/(bar/*useBar*/, baz/*useBaz*/, bang/*useBang*/);
8+
////import [|/*importFoo*/foo|], {bar} from "jquery";
9+
////import * as [|/*importBaz*/baz|] from "jquery";
10+
////import [|/*importBang*/bang|] = require("jquery");
11+
////[|foo/*useFoo*/|]([|bar/*useBar*/|], [|baz/*useBaz*/|], [|bang/*useBang*/|]);
1212

1313
verify.quickInfoAt("useFoo", "import foo");
1414
verify.goToDefinition({

tests/cases/fourslash/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path='fourslash.ts'/>
22

33
// @Filename: b.ts
4-
////import n = require('./a/*1*/');
4+
////import n = require([|'./a/*1*/'|]);
55
////var x = new n.Foo();
66

77
// @Filename: a.ts

tests/cases/fourslash/definitionNameOnEnumMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//// secondMember,
66
//// thirdMember
77
////}
8-
////var enumMember = e./*1*/thirdMember;
8+
////var enumMember = e.[|/*1*/thirdMember|];
99

1010
goTo.marker("1");
1111
verify.goToDefinitionName("thirdMember", "e");

tests/cases/fourslash/duplicatePackageServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @noImplicitReferences: true
33

44
// @Filename: /node_modules/a/index.d.ts
5-
////import /*useAX*/[|{| "isWriteAccess": true, "isDefinition": true |}X|] from "x";
5+
////import [|{| "name": "useAX", "isWriteAccess": true, "isDefinition": true |}X|] from "x";
66
////export function a(x: [|X|]): void;
77

88
// @Filename: /node_modules/a/node_modules/x/index.d.ts
@@ -14,7 +14,7 @@
1414
////{ "name": "x", "version": "1.2.3" }
1515

1616
// @Filename: /node_modules/b/index.d.ts
17-
////import /*useBX*/[|{| "isWriteAccess": true, "isDefinition": true |}X|] from "x";
17+
////import [|{| "name": "useBX", "isWriteAccess": true, "isDefinition": true |}X|] from "x";
1818
////export const b: [|X|];
1919

2020
// @Filename: /node_modules/b/node_modules/x/index.d.ts

tests/cases/fourslash/findAllRefsForDefaultExport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// @Filename: b.ts
77
////import [|{| "isWriteAccess": true, "isDefinition": true |}g|] from "./a";
8-
/////*ref*/[|g|]();
8+
////[|/*ref*/g|]();
99

1010
// @Filename: c.ts
1111
////import { f } from "./a";

tests/cases/fourslash/fourslash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ declare namespace FourSlashInterface {
193193
* `verify.goToDefinition("a", ["b", "bb"]);` verifies that "a" has multiple definitions available.
194194
*/
195195
goToDefinition(startMarkerNames: string | string[], endMarkerNames: string | string[]): void;
196+
goToDefinition(startMarkerNames: string | string[], endMarkerNames: string | string[], range: Range): void;
196197
/** Performs `goToDefinition` for each pair. */
197198
goToDefinition(startsAndEnds: [string | string[], string | string[]][]): void;
198199
/** Performs `goToDefinition` on each key and value. */

tests/cases/fourslash/goToDefinitionAcrossMultipleProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
//@Filename: c.ts
1010
/////// <reference path="a.ts" />
1111
/////// <reference path="b.ts" />
12-
/////*use*/x++;
12+
////[|/*use*/x|]++;
1313

1414
verify.goToDefinition("use", ["def1", "def2"]);

tests/cases/fourslash/goToDefinitionAlias.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
////}
88
////
99
////// Type position
10-
////var t1: /*alias1Type*/alias1.IFoo;
11-
////var t2: Module./*alias2Type*/alias2.IFoo;
10+
////var t1: [|/*alias1Type*/alias1|].IFoo;
11+
////var t2: Module.[|/*alias2Type*/alias2|].IFoo;
1212
////
1313
////// Value posistion
14-
////var v1 = new /*alias1Value*/alias1.Foo();
15-
////var v2 = new Module./*alias2Value*/alias2.Foo();
14+
////var v1 = new [|/*alias1Value*/alias1|].Foo();
15+
////var v2 = new Module.[|/*alias2Value*/alias2|].Foo();
1616

1717

1818
// @Filename: a.ts

0 commit comments

Comments
 (0)