Skip to content

Commit 493ddc2

Browse files
authored
Remove non-baselining fourslash FAR validation (#48564)
* Fix fourslash failures * Delete unused FAR fourslash helpers
1 parent 99ea99b commit 493ddc2

21 files changed

+22609
-266
lines changed

src/harness/fourslashImpl.ts

Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,83 +1122,18 @@ namespace FourSlash {
11221122
}
11231123
}
11241124

1125-
private verifyDocumentHighlightsRespectFilesList(files: readonly string[]): void {
1126-
const startFile = this.activeFile.fileName;
1127-
for (const fileName of files) {
1128-
const searchFileNames = startFile === fileName ? [startFile] : [startFile, fileName];
1129-
const highlights = this.getDocumentHighlightsAtCurrentPosition(searchFileNames);
1130-
if (highlights && !highlights.every(dh => ts.contains(searchFileNames, dh.fileName))) {
1131-
this.raiseError(`When asking for document highlights only in files ${searchFileNames}, got document highlights in ${unique(highlights, dh => dh.fileName)}`);
1132-
}
1133-
}
1125+
public verifyBaselineFindAllReferences(...markerNames: string[]) {
1126+
ts.Debug.assert(markerNames.length > 0, "Must pass at least one marker name to `verifyBaselineFindAllReferences()`");
1127+
this.verifyBaselineFindAllReferencesWorker("", markerNames);
11341128
}
11351129

1136-
public verifyReferenceGroups(starts: ArrayOrSingle<string> | ArrayOrSingle<Range>, parts: readonly FourSlashInterface.ReferenceGroup[]): void {
1137-
interface ReferenceGroupJson {
1138-
definition: string | { text: string, range: ts.TextSpan };
1139-
references: ts.ReferenceEntry[];
1140-
}
1141-
interface RangeMarkerData {
1142-
id?: string;
1143-
isWriteAccess?: boolean,
1144-
isDefinition?: boolean,
1145-
isInString?: true,
1146-
contextRangeIndex?: number,
1147-
contextRangeDelta?: number,
1148-
contextRangeId?: string
1149-
}
1150-
const fullExpected = ts.map<FourSlashInterface.ReferenceGroup, ReferenceGroupJson>(parts, ({ definition, ranges }) => ({
1151-
definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) },
1152-
references: ranges.map<ts.ReferenceEntry>(r => {
1153-
const { isWriteAccess = false, isDefinition = false, isInString, contextRangeIndex, contextRangeDelta, contextRangeId } = (r.marker && r.marker.data || {}) as RangeMarkerData;
1154-
let contextSpan: ts.TextSpan | undefined;
1155-
if (contextRangeDelta !== undefined) {
1156-
const allRanges = this.getRanges();
1157-
const index = allRanges.indexOf(r);
1158-
if (index !== -1) {
1159-
contextSpan = ts.createTextSpanFromRange(allRanges[index + contextRangeDelta]);
1160-
}
1161-
}
1162-
else if (contextRangeId !== undefined) {
1163-
const allRanges = this.getRanges();
1164-
const contextRange = ts.find(allRanges, range => (range.marker?.data as RangeMarkerData)?.id === contextRangeId);
1165-
if (contextRange) {
1166-
contextSpan = ts.createTextSpanFromRange(contextRange);
1167-
}
1168-
}
1169-
else if (contextRangeIndex !== undefined) {
1170-
contextSpan = ts.createTextSpanFromRange(this.getRanges()[contextRangeIndex]);
1171-
}
1172-
return {
1173-
textSpan: ts.createTextSpanFromRange(r),
1174-
fileName: r.fileName,
1175-
...(contextSpan ? { contextSpan } : undefined),
1176-
isWriteAccess,
1177-
isDefinition,
1178-
...(isInString ? { isInString: true } : undefined),
1179-
};
1180-
}),
1181-
}));
1182-
1183-
for (const start of toArray<string | Range>(starts)) {
1184-
this.goToMarkerOrRange(start);
1185-
const fullActual = ts.map<ts.ReferencedSymbol, ReferenceGroupJson>(this.findReferencesAtCaret(), ({ definition, references }, i) => {
1186-
const text = definition.displayParts.map(d => d.text).join("");
1187-
return {
1188-
definition: fullExpected.length > i && typeof fullExpected[i].definition === "string" ? text : { text, range: definition.textSpan },
1189-
references,
1190-
};
1191-
});
1192-
this.assertObjectsEqual(fullActual, fullExpected);
1193-
1194-
if (parts) {
1195-
this.verifyDocumentHighlightsRespectFilesList(unique(ts.flatMap(parts, p => p.ranges), r => r.fileName));
1196-
}
1197-
}
1130+
// Used when a single test needs to produce multiple baselines
1131+
public verifyBaselineFindAllReferencesMulti(seq: number, ...markerNames: string[]) {
1132+
ts.Debug.assert(markerNames.length > 0, "Must pass at least one marker name to `baselineFindAllReferences()`");
1133+
this.verifyBaselineFindAllReferencesWorker(`.${seq}`, markerNames);
11981134
}
11991135

1200-
public verifyBaselineFindAllReferences(...markerNames: string[]) {
1201-
ts.Debug.assert(markerNames.length > 0, "Must pass at least one marker name to `baselineFindAllReferences()`");
1136+
private verifyBaselineFindAllReferencesWorker(suffix: string, markerNames: string[]) {
12021137
const baseline = markerNames.map(markerName => {
12031138
this.goToMarker(markerName);
12041139
const marker = this.getMarkerByName(markerName);
@@ -1213,7 +1148,7 @@ namespace FourSlash {
12131148
// Write response JSON
12141149
return baselineContent + JSON.stringify(references, undefined, 2);
12151150
}).join("\n\n");
1216-
Harness.Baseline.runBaseline(this.getBaselineFileNameForContainingTestFile(".baseline.jsonc"), baseline);
1151+
Harness.Baseline.runBaseline(this.getBaselineFileNameForContainingTestFile(`${suffix}.baseline.jsonc`), baseline);
12171152
}
12181153

12191154
public verifyBaselineGetFileReferences(fileName: string) {
@@ -1280,11 +1215,6 @@ namespace FourSlash {
12801215
}
12811216
}
12821217

1283-
public verifySingleReferenceGroup(definition: FourSlashInterface.ReferenceGroupDefinition, ranges?: Range[] | string) {
1284-
ranges = ts.isString(ranges) ? this.rangesByText().get(ranges)! : ranges || this.getRanges();
1285-
this.verifyReferenceGroups(ranges, [{ definition, ranges }]);
1286-
}
1287-
12881218
private assertObjectsEqual<T>(fullActual: T, fullExpected: T, msgPrefix = ""): void {
12891219
const recur = <U>(actual: U, expected: U, path: string) => {
12901220
const fail = (msg: string) => {
@@ -2403,15 +2333,6 @@ namespace FourSlash {
24032333
this.goToPosition(len);
24042334
}
24052335

2406-
private goToMarkerOrRange(markerOrRange: string | Range) {
2407-
if (typeof markerOrRange === "string") {
2408-
this.goToMarker(markerOrRange);
2409-
}
2410-
else {
2411-
this.goToRangeStart(markerOrRange);
2412-
}
2413-
}
2414-
24152336
public goToRangeStart({ fileName, pos }: Range) {
24162337
this.openFile(fileName);
24172338
this.goToPosition(pos);

src/harness/fourslashInterfaceImpl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ namespace FourSlashInterface {
352352
this.state.verifyBaselineFindAllReferences(...markerNames);
353353
}
354354

355-
public baselineGetFileReferences(fileName: string) {
356-
this.state.verifyBaselineGetFileReferences(fileName);
355+
public baselineFindAllReferencesMulti(seq: number, ...markerNames: string[]) {
356+
this.state.verifyBaselineFindAllReferencesMulti(seq, ...markerNames);
357357
}
358358

359-
public singleReferenceGroup(definition: ReferenceGroupDefinition, ranges?: FourSlash.Range[] | string) {
360-
this.state.verifySingleReferenceGroup(definition, ranges);
359+
public baselineGetFileReferences(fileName: string) {
360+
this.state.verifyBaselineGetFileReferences(fileName);
361361
}
362362

363363
public findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]) {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
2+
// export class Test{
3+
//
4+
// constructor(){
5+
//
6+
// }
7+
//
8+
// public /*FIND ALL REFS*/[|start|](){
9+
// return this;
10+
// }
11+
//
12+
// public stop(){
13+
// return this;
14+
// }
15+
// }
16+
17+
// === /tests/cases/fourslash/findAllRefsOnDefinition.ts ===
18+
// import Second = require("./findAllRefsOnDefinition-import");
19+
//
20+
// var second = new Second.Test()
21+
// second.[|start|]();
22+
// second.stop();
23+
24+
[
25+
{
26+
"definition": {
27+
"containerKind": "",
28+
"containerName": "",
29+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition-import.ts",
30+
"kind": "method",
31+
"name": "(method) Test.start(): this",
32+
"textSpan": {
33+
"start": 58,
34+
"length": 5
35+
},
36+
"displayParts": [
37+
{
38+
"text": "(",
39+
"kind": "punctuation"
40+
},
41+
{
42+
"text": "method",
43+
"kind": "text"
44+
},
45+
{
46+
"text": ")",
47+
"kind": "punctuation"
48+
},
49+
{
50+
"text": " ",
51+
"kind": "space"
52+
},
53+
{
54+
"text": "Test",
55+
"kind": "className"
56+
},
57+
{
58+
"text": ".",
59+
"kind": "punctuation"
60+
},
61+
{
62+
"text": "start",
63+
"kind": "methodName"
64+
},
65+
{
66+
"text": "(",
67+
"kind": "punctuation"
68+
},
69+
{
70+
"text": ")",
71+
"kind": "punctuation"
72+
},
73+
{
74+
"text": ":",
75+
"kind": "punctuation"
76+
},
77+
{
78+
"text": " ",
79+
"kind": "space"
80+
},
81+
{
82+
"text": "this",
83+
"kind": "keyword"
84+
}
85+
],
86+
"contextSpan": {
87+
"start": 51,
88+
"length": 42
89+
}
90+
},
91+
"references": [
92+
{
93+
"textSpan": {
94+
"start": 58,
95+
"length": 5
96+
},
97+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition-import.ts",
98+
"contextSpan": {
99+
"start": 51,
100+
"length": 42
101+
},
102+
"isWriteAccess": true,
103+
"isDefinition": true
104+
},
105+
{
106+
"textSpan": {
107+
"start": 100,
108+
"length": 5
109+
},
110+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition.ts",
111+
"isWriteAccess": false,
112+
"isDefinition": false
113+
}
114+
]
115+
}
116+
]
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
2+
// export class Test{
3+
//
4+
// constructor(){
5+
//
6+
// }
7+
//
8+
// public /*FIND ALL REFS*/[|start|](){
9+
// return this;
10+
// }
11+
//
12+
// public stop(){
13+
// return this;
14+
// }
15+
// }
16+
17+
// === /tests/cases/fourslash/findAllRefsOnDefinition.ts ===
18+
// import Second = require("./findAllRefsOnDefinition-import");
19+
//
20+
// var second = new Second.Test()
21+
// second.[|start|]();
22+
// second.stop();
23+
24+
[
25+
{
26+
"definition": {
27+
"containerKind": "",
28+
"containerName": "",
29+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition-import.ts",
30+
"kind": "method",
31+
"name": "(method) Test.start(): this",
32+
"textSpan": {
33+
"start": 58,
34+
"length": 5
35+
},
36+
"displayParts": [
37+
{
38+
"text": "(",
39+
"kind": "punctuation"
40+
},
41+
{
42+
"text": "method",
43+
"kind": "text"
44+
},
45+
{
46+
"text": ")",
47+
"kind": "punctuation"
48+
},
49+
{
50+
"text": " ",
51+
"kind": "space"
52+
},
53+
{
54+
"text": "Test",
55+
"kind": "className"
56+
},
57+
{
58+
"text": ".",
59+
"kind": "punctuation"
60+
},
61+
{
62+
"text": "start",
63+
"kind": "methodName"
64+
},
65+
{
66+
"text": "(",
67+
"kind": "punctuation"
68+
},
69+
{
70+
"text": ")",
71+
"kind": "punctuation"
72+
},
73+
{
74+
"text": ":",
75+
"kind": "punctuation"
76+
},
77+
{
78+
"text": " ",
79+
"kind": "space"
80+
},
81+
{
82+
"text": "this",
83+
"kind": "keyword"
84+
}
85+
],
86+
"contextSpan": {
87+
"start": 51,
88+
"length": 42
89+
}
90+
},
91+
"references": [
92+
{
93+
"textSpan": {
94+
"start": 58,
95+
"length": 5
96+
},
97+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition-import.ts",
98+
"contextSpan": {
99+
"start": 51,
100+
"length": 42
101+
},
102+
"isWriteAccess": true,
103+
"isDefinition": true
104+
},
105+
{
106+
"textSpan": {
107+
"start": 100,
108+
"length": 5
109+
},
110+
"fileName": "/tests/cases/fourslash/findAllRefsOnDefinition.ts",
111+
"isWriteAccess": false,
112+
"isDefinition": false
113+
}
114+
]
115+
}
116+
]

0 commit comments

Comments
 (0)