Skip to content

Commit 100712e

Browse files
committed
Replace goToDefinitionIs with baselineGetDefinitionAtPosition
1 parent 8f381b0 commit 100712e

File tree

53 files changed

+584911
-183
lines changed

Some content is hidden

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

53 files changed

+584911
-183
lines changed

src/harness/fourslashImpl.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,6 @@ export class TestState {
741741
}
742742
}
743743

744-
public verifyGoToDefinitionIs(endMarker: ArrayOrSingle<string>) {
745-
this.verifyGoToXWorker(/*startMarker*/ undefined, toArray(endMarker), () => this.getGoToDefinition());
746-
}
747-
748744
private getGoToDefinition(): readonly ts.DefinitionInfo[] {
749745
return this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition)!;
750746
}
@@ -753,73 +749,6 @@ export class TestState {
753749
return this.languageService.getDefinitionAndBoundSpan(this.activeFile.fileName, this.currentCaretPosition)!;
754750
}
755751

756-
private verifyGoToXWorker(startMarker: string | undefined, endMarkers: readonly (string | { marker?: string, file?: string, unverified?: boolean })[], getDefs: () => readonly ts.DefinitionInfo[] | ts.DefinitionInfoAndBoundSpan | undefined, startMarkerName?: string) {
757-
const defs = getDefs();
758-
let definitions: readonly ts.DefinitionInfo[];
759-
let testName: string;
760-
761-
if (!defs || ts.isArray(defs)) {
762-
definitions = defs as ts.DefinitionInfo[] || [];
763-
testName = "goToDefinitions";
764-
}
765-
else {
766-
this.verifyDefinitionTextSpan(defs, startMarkerName!);
767-
768-
definitions = defs.definitions!; // TODO: GH#18217
769-
testName = "goToDefinitionsAndBoundSpan";
770-
}
771-
772-
if (endMarkers.length !== definitions.length) {
773-
const markers = definitions.map(d => ({ text: "HERE", fileName: d.fileName, position: d.textSpan.start }));
774-
const actual = this.renderMarkers(markers);
775-
this.raiseError(`${testName} failed - expected to find ${endMarkers.length} definitions but got ${definitions.length}\n\n${actual}`);
776-
}
777-
778-
ts.zipWith(endMarkers, definitions, (endMarkerOrFileResult, definition, i) => {
779-
const markerName = typeof endMarkerOrFileResult === "string" ? endMarkerOrFileResult : endMarkerOrFileResult.marker;
780-
const marker = markerName !== undefined ? this.getMarkerByName(markerName) : undefined;
781-
const expectedFileName = marker?.fileName || typeof endMarkerOrFileResult !== "string" && endMarkerOrFileResult.file;
782-
ts.Debug.assert(typeof expectedFileName === "string");
783-
const expectedPosition = marker?.position || 0;
784-
if (ts.comparePaths(expectedFileName, definition.fileName, /*ignoreCase*/ true) !== ts.Comparison.EqualTo || expectedPosition !== definition.textSpan.start) {
785-
const markers = [{ text: "EXPECTED", fileName: expectedFileName, position: expectedPosition }, { text: "ACTUAL", fileName: definition.fileName, position: definition.textSpan.start }];
786-
const text = this.renderMarkers(markers);
787-
this.raiseError(`${testName} failed for definition ${markerName || expectedFileName} (${i}): expected ${expectedFileName} at ${expectedPosition}, got ${definition.fileName} at ${definition.textSpan.start}\n\n${text}\n`);
788-
}
789-
if (definition.unverified && (typeof endMarkerOrFileResult === "string" || !endMarkerOrFileResult.unverified)) {
790-
const isFileResult = typeof endMarkerOrFileResult !== "string" && !!endMarkerOrFileResult.file;
791-
this.raiseError(
792-
`${testName} failed for definition ${markerName || expectedFileName} (${i}): The actual definition was an \`unverified\` result. Use:\n\n` +
793-
` verify.goToDefinition(${startMarker === undefined ? "startMarker" : `"${startMarker}"`}, { ${isFileResult ? `file: "${expectedFileName}"` : `marker: "${markerName}"`}, unverified: true })\n\n` +
794-
`if this is expected.`
795-
);
796-
}
797-
});
798-
}
799-
800-
private verifyDefinitionTextSpan(defs: ts.DefinitionInfoAndBoundSpan, startMarkerName: string) {
801-
const range = this.testData.ranges.find(range => this.markerName(range.marker!) === startMarkerName);
802-
803-
if (!range && !defs.textSpan) {
804-
return;
805-
}
806-
807-
if (!range) {
808-
const marker = this.getMarkerByName(startMarkerName);
809-
const startFile = marker.fileName;
810-
const fileContent = this.getFileContent(startFile);
811-
const spanContent = fileContent.slice(defs.textSpan.start, ts.textSpanEnd(defs.textSpan));
812-
const spanContentWithMarker = spanContent.slice(0, marker.position - defs.textSpan.start) + `/*${startMarkerName}*/` + spanContent.slice(marker.position - defs.textSpan.start);
813-
const suggestedFileContent = (fileContent.slice(0, defs.textSpan.start) + `\x1b[1;4m[|${spanContentWithMarker}|]\x1b[0;31m` + fileContent.slice(ts.textSpanEnd(defs.textSpan)))
814-
.split(/\r?\n/).map(line => " ".repeat(6) + line).join(ts.sys.newLine);
815-
this.raiseError(`goToDefinitionsAndBoundSpan failed. Found a starting TextSpan around '${spanContent}' in '${startFile}' (at position ${defs.textSpan.start}). `
816-
+ `If this is the correct input span, put a fourslash range around it: \n\n${suggestedFileContent}\n`);
817-
}
818-
else {
819-
this.assertTextSpanEqualsRange(defs.textSpan, range, "goToDefinitionsAndBoundSpan failed");
820-
}
821-
}
822-
823752
private renderMarkers(markers: { text: string, fileName: string, position: number }[], useTerminalBoldSequence = true) {
824753
const filesToDisplay = ts.deduplicate(markers.map(m => m.fileName), ts.equateValues);
825754
return filesToDisplay.map(fileName => {
@@ -4120,12 +4049,6 @@ export class TestState {
41204049
Harness.Baseline.runBaseline(baselineFile, text);
41214050
}
41224051

4123-
private assertTextSpanEqualsRange(span: ts.TextSpan, range: Range, message?: string) {
4124-
if (!textSpanEqualsRange(span, range)) {
4125-
this.raiseError(`${prefixMessage(message)}Expected to find TextSpan ${JSON.stringify({ start: range.pos, length: range.end - range.pos })} but got ${JSON.stringify(span)} instead.`);
4126-
}
4127-
}
4128-
41294052
private getLineContent(index: number) {
41304053
const text = this.getFileContent(this.activeFile.fileName);
41314054
const pos = this.languageServiceAdapterHost.lineAndCharacterToPosition(this.activeFile.fileName, { line: index, character: 0 });
@@ -4308,14 +4231,6 @@ export class TestState {
43084231
}
43094232
}
43104233

4311-
function prefixMessage(message: string | undefined) {
4312-
return message ? `${message} - ` : "";
4313-
}
4314-
4315-
function textSpanEqualsRange(span: ts.TextSpan, range: Range) {
4316-
return span.start === range.pos && span.length === range.end - range.pos;
4317-
}
4318-
43194234
function updateTextRangeForTextChanges({ pos, end }: ts.TextRange, textChanges: readonly ts.TextChange[]): ts.TextRange {
43204235
forEachTextChange(textChanges, change => {
43214236
const update = (p: number): number => updatePosition(p, change.span.start, ts.textSpanEnd(change.span), change.newText);

src/harness/fourslashInterfaceImpl.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,6 @@ export class Verify extends VerifyNegatable {
306306
this.state.verifyFormatDocumentChangesNothing();
307307
}
308308

309-
public goToDefinitionIs(endMarkers: ArrayOrSingle<string>) {
310-
this.state.verifyGoToDefinitionIs(endMarkers);
311-
}
312-
313309
public verifyGetEmitOutputForCurrentFile(expected: string): void {
314310
this.state.verifyGetEmitOutputForCurrentFile(expected);
315311
}

tests/baselines/reference/declarationMapsEnableMapping_NoInline.baseline.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
// const instance = new mod.Foo();
8787
// instance./*GOTO DEF*/[|methodName|]({member: 12});
8888

89+
// === Details ===
90+
[
91+
{
92+
"containerKind": "",
93+
"containerName": "",
94+
"kind": "",
95+
"name": ""
96+
}
97+
]
98+
99+
100+
101+
// === getDefinitionAtPosition ===
102+
// === /index.ts ===
103+
// export class Foo {
104+
// member: string;
105+
// [|methodName|](propName: SomeType): SomeType { return propName; }
106+
// otherMethod() {
107+
// if (Math.random() > 0.5) {
108+
// return {x: 42};
109+
// }
110+
// return {y: "yes"};
111+
// }
112+
// }
113+
//
114+
// export interface SomeType {
115+
// member: number;
116+
// }
117+
118+
// === /mymodule.ts ===
119+
// import * as mod from "/dist/index";
120+
// const instance = new mod.Foo();
121+
// instance./*GOTO DEF POS*/methodName({member: 12});
122+
89123
// === Details ===
90124
[
91125
{

tests/baselines/reference/declarationMapsEnableMapping_NoInlineSources.baseline.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
// const instance = new mod.Foo();
8787
// instance./*GOTO DEF*/[|methodName|]({member: 12});
8888

89+
// === Details ===
90+
[
91+
{
92+
"containerKind": "",
93+
"containerName": "",
94+
"kind": "",
95+
"name": ""
96+
}
97+
]
98+
99+
100+
101+
// === getDefinitionAtPosition ===
102+
// === /index.ts ===
103+
// export class Foo {
104+
// member: string;
105+
// [|methodName|](propName: SomeType): SomeType { return propName; }
106+
// otherMethod() {
107+
// if (Math.random() > 0.5) {
108+
// return {x: 42};
109+
// }
110+
// return {y: "yes"};
111+
// }
112+
// }
113+
//
114+
// export interface SomeType {
115+
// member: number;
116+
// }
117+
118+
// === /mymodule.ts ===
119+
// import * as mod from "/dist/index";
120+
// const instance = new mod.Foo();
121+
// instance./*GOTO DEF POS*/methodName({member: 12});
122+
89123
// === Details ===
90124
[
91125
{

tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
// const instance = new mod.Foo();
8787
// instance./*GOTO DEF*/[|methodName|]({member: 12});
8888

89+
// === Details ===
90+
[
91+
{
92+
"containerKind": "",
93+
"containerName": "",
94+
"kind": "",
95+
"name": ""
96+
}
97+
]
98+
99+
100+
101+
// === getDefinitionAtPosition ===
102+
// === /index.ts ===
103+
// export class Foo {
104+
// member: string;
105+
// [|methodName|](propName: SomeType): SomeType { return propName; }
106+
// otherMethod() {
107+
// if (Math.random() > 0.5) {
108+
// return {x: 42};
109+
// }
110+
// return {y: "yes"};
111+
// }
112+
// }
113+
//
114+
// export interface SomeType {
115+
// member: number;
116+
// }
117+
118+
// === /mymodule.ts ===
119+
// import * as mod from "/dist/index";
120+
// const instance = new mod.Foo();
121+
// instance./*GOTO DEF POS*/methodName({member: 12});
122+
89123
// === Details ===
90124
[
91125
{

tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
// const instance = new mod.Foo();
8787
// instance./*GOTO DEF*/[|methodName|]({member: 12});
8888

89+
// === Details ===
90+
[
91+
{
92+
"containerKind": "",
93+
"containerName": "",
94+
"kind": "",
95+
"name": ""
96+
}
97+
]
98+
99+
100+
101+
// === getDefinitionAtPosition ===
102+
// === /index.ts ===
103+
// export class Foo {
104+
// member: string;
105+
// [|methodName|](propName: SomeType): SomeType { return propName; }
106+
// otherMethod() {
107+
// if (Math.random() > 0.5) {
108+
// return {x: 42};
109+
// }
110+
// return {y: "yes"};
111+
// }
112+
// }
113+
//
114+
// export interface SomeType {
115+
// member: number;
116+
// }
117+
118+
// === /mymodule.ts ===
119+
// import * as mod from "/dist/index";
120+
// const instance = new mod.Foo();
121+
// instance./*GOTO DEF POS*/methodName({member: 12});
122+
89123
// === Details ===
90124
[
91125
{

tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping3.baseline.jsonc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686
// const instance = new mod.Foo();
8787
// instance./*GOTO DEF*/[|methodName|]({member: 12});
8888

89+
// === Details ===
90+
[
91+
{
92+
"containerKind": "",
93+
"containerName": "",
94+
"kind": "",
95+
"name": ""
96+
}
97+
]
98+
99+
100+
101+
// === getDefinitionAtPosition ===
102+
// === /index.ts ===
103+
// export class Foo {
104+
// member: string;
105+
// [|methodName|](propName: SomeType): SomeType { return propName; }
106+
// otherMethod() {
107+
// if (Math.random() > 0.5) {
108+
// return {x: 42};
109+
// }
110+
// return {y: "yes"};
111+
// }
112+
// }
113+
//
114+
// export interface SomeType {
115+
// member: number;
116+
// }
117+
118+
// === /mymodule.ts ===
119+
// import * as mod from "/dist/index";
120+
// const instance = new mod.Foo();
121+
// instance./*GOTO DEF POS*/methodName({member: 12});
122+
89123
// === Details ===
90124
[
91125
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// === getDefinitionAtPosition ===
2+
// === /node_modules/a/src/index.ts ===
3+
// export class [|Foo|] {
4+
// }
5+
//
6+
7+
// === /index.ts ===
8+
// import { Foo/*GOTO DEF POS*/ } from "a";
9+
10+
// === Details ===
11+
[
12+
{
13+
"containerKind": "",
14+
"containerName": "",
15+
"kind": "",
16+
"name": ""
17+
}
18+
]

0 commit comments

Comments
 (0)