Skip to content

Commit 5e848bf

Browse files
committed
Definition details separate and no Json baselines
1 parent d4da199 commit 5e848bf

File tree

865 files changed

+87052
-212130
lines changed

Some content is hidden

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

865 files changed

+87052
-212130
lines changed

src/harness/fourslashImpl.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,11 @@ export class TestState {
752752
) {
753753
this.goToMarkerOrNameOrRange(markerOrRange);
754754
const defs = getDefs();
755-
return this.baselineReferencesWorker<ReturnType<typeof getDefs>, ts.DefinitionInfo | ts.ImplementationLocation>(
755+
return this.baselineReferencesWorker<ts.DefinitionInfo | ts.ImplementationLocation>(
756756
refType,
757757
markerOrRange,
758-
defs,
759-
defs => defs ? ts.isArray(defs) ? defs : defs.definitions : undefined,
760-
defs => defs && !ts.isArray(defs) ? "// === TextSpan ===\n" + this.getBaselineContentForGroupedReferences(
758+
defs ? ts.isArray(defs) ? defs : defs.definitions : undefined,
759+
defs && !ts.isArray(defs) ? "// === TextSpan ===\n" + this.getBaselineContentForGroupedReferences(
761760
refType,
762761
[[{ fileName: this.activeFile.fileName, textSpan: defs.textSpan }]],
763762
markerOrRange,
@@ -1213,20 +1212,28 @@ export class TestState {
12131212
return this.baselineReferencesWorker(
12141213
"/*FIND ALL REFS*/",
12151214
markerOrRange,
1216-
references,
1217-
references => ts.flatMap(references, (r, def) => {
1215+
ts.flatMap(references, (r, def) => {
12181216
defIdMap.set(r.definition, def);
12191217
r.references.forEach(r => defIdMap.set(r, def));
12201218
return r.references;
12211219
}),
1222-
references => references ? "// === Definitions ===\n" + this.baselineReferencesWorker(
1223-
"/*FIND ALL REFS*/",
1224-
markerOrRange,
1225-
references.map(r => r.definition),
1226-
ts.identity,
1227-
/*skipJson*/ true,
1228-
def => `defId: ${defIdMap.get(def)}`,
1229-
) : "",
1220+
references ? "// === Definitions ===\n" +
1221+
this.baselineReferencesWorker(
1222+
"/*FIND ALL REFS*/",
1223+
markerOrRange,
1224+
references.map(r => r.definition),
1225+
/*additionalBaseline*/ undefined,
1226+
def => `defId: ${defIdMap.get(def)}`,
1227+
/*skipExtraInfo*/ true,
1228+
) +
1229+
"// === Definitions Details ===\n" +
1230+
JSON.stringify(references.map(r => ({
1231+
defId: defIdMap.get(r.definition),
1232+
...r.definition,
1233+
fileName: undefined,
1234+
textSpan: undefined,
1235+
contextSpan: undefined,
1236+
})), undefined, " ") : "",
12301237
ref => `defId: ${defIdMap.get(ref)}`,
12311238
);
12321239
}
@@ -1241,49 +1248,46 @@ export class TestState {
12411248
"/*FIND ALL REFS*/",
12421249
/*markerName*/ undefined,
12431250
references,
1244-
ts.identity,
12451251
);
12461252
}
12471253

1248-
private baselineReferencesWorker<R, T extends ts.DocumentSpan>(
1254+
private baselineReferencesWorker<T extends ts.DocumentSpan>(
12491255
refType: string,
12501256
markerOrRange: MarkerOrNameOrRange | undefined,
1251-
result: R,
1252-
getDocumentSpanArray: (result: R) => readonly T[] | undefined,
1253-
skipJsonOrGetAdditionalBaseline?: true | ((result: R) => string),
1254-
documentSpanToPrefix?: (span: T) => string,
1257+
spans: readonly T[] | undefined,
1258+
additionalBaseline?: string,
1259+
documentSpanId?: (span: T) => string,
1260+
skipExtraInfo?: boolean,
12551261
endMarker?: string,
12561262
startMarkerPrefix?: (span: T) => string | undefined,
12571263
endMarkerSuffix?: (span: T) => string | undefined,
12581264
ignoredDocumentSpanProperties?: readonly string[],
12591265
): string {
1260-
const spans = getDocumentSpanArray(result);
12611266
const spansByFile = spans ? ts.group(spans, span => span.fileName) : ts.emptyArray;
12621267
// Write input files
12631268
const baselineContent = this.getBaselineContentForGroupedReferences(
12641269
refType,
12651270
spansByFile,
12661271
markerOrRange,
1267-
// Skip additional marker file since its already added in prev baseline,
1268-
skipJsonOrGetAdditionalBaseline === true,
1269-
documentSpanToPrefix,
1272+
documentSpanId,
1273+
skipExtraInfo,
12701274
endMarker,
12711275
startMarkerPrefix,
12721276
endMarkerSuffix,
12731277
ignoredDocumentSpanProperties,
12741278
);
1275-
if (skipJsonOrGetAdditionalBaseline === true) return baselineContent;
1276-
const additionalBaseline = skipJsonOrGetAdditionalBaseline?.(result) || "";
12771279
// Write response JSON
1278-
return baselineContent + additionalBaseline + JSON.stringify(result, undefined, 2);
1280+
return baselineContent +
1281+
(additionalBaseline || "") +
1282+
(!spans?.length ? JSON.stringify(spans, undefined, 2) : "");
12791283
}
12801284

12811285
private getBaselineContentForGroupedReferences<T extends ts.DocumentSpan>(
12821286
refType: string,
12831287
refsByFile: readonly (readonly T[])[],
12841288
markerOrRange: MarkerOrNameOrRange | undefined,
1285-
skipMarkerOnlyFile?: boolean,
1286-
documentSpanToPrefix?: (span: T) => string,
1289+
documentSpanId?: (span: T) => string,
1290+
skipExtraInfo?: boolean,
12871291
endMarker?: string,
12881292
startMarkerPrefix?: (span: T) => string | undefined,
12891293
endMarkerSuffix?: (span: T) => string | undefined,
@@ -1314,15 +1318,17 @@ export class TestState {
13141318
baselineContent += `// === ${group[0].fileName} ===\n// Unavailable file content:\n`;
13151319
for (const span of group) {
13161320
baselineContent += `// textSpan: ${JSON.stringify(span.textSpan)}${span.contextSpan ? `, contextSpan: ${JSON.stringify(span.contextSpan)}` : ""}`;
1317-
const text = convertDocumentSpanToString(span, documentSpanToPrefix?.(span));
1321+
const text = !skipExtraInfo ?
1322+
convertDocumentSpanToString(span, documentSpanId?.(span)) :
1323+
documentSpanId?.(span);
13181324
if (text) baselineContent += ` ${text}`;
13191325
baselineContent = "\n\n";
13201326
}
13211327
foundMarker ||= marker?.fileName === group[0].fileName;
13221328
}
13231329
}
13241330
}
1325-
if (!skipMarkerOnlyFile && !foundMarker && marker?.fileName) {
1331+
if (!skipExtraInfo && !foundMarker && marker?.fileName) {
13261332
const content = this.getFileContent(marker.fileName);
13271333
const newContent = `=== ${marker.fileName} ===\n` +
13281334
content.slice(0, marker.position) +
@@ -1441,7 +1447,9 @@ export class TestState {
14411447
if (span) {
14421448
switch (type) {
14431449
case "textStart":
1444-
let text = convertDocumentSpanToString(span, documentSpanToPrefix?.(span), ignoredDocumentSpanProperties);
1450+
let text = !skipExtraInfo ?
1451+
convertDocumentSpanToString(span, documentSpanId?.(span), ignoredDocumentSpanProperties) :
1452+
documentSpanId?.(span);
14451453
const contextId = spanToContextId.get(span);
14461454
if (contextId !== undefined) {
14471455
text = `contextId: ${contextId}` + (text ? ", " : "") + text;
@@ -1690,9 +1698,9 @@ export class TestState {
16901698
"/*RENAME*/",
16911699
markerOrRange,
16921700
locations,
1693-
ts.identity,
1694-
/*skipJsonOrGetAdditionalBaseline*/ undefined,
1695-
/*documentSpanToPrefix*/ undefined,
1701+
/*additionalBaseline*/ undefined,
1702+
/*documentSpanId*/ undefined,
1703+
/*skipExtraInfo*/ undefined,
16961704
"RENAME|]",
16971705
span => span.prefixText ? `/*START PREFIX*/${span.prefixText}` : "",
16981706
span => span.suffixText ? `${span.suffixText}/*END SUFFIX*/` : "",
@@ -3549,7 +3557,6 @@ export class TestState {
35493557
"/*OCCURENCES*/",
35503558
markerOrRange,
35513559
occurrences,
3552-
ts.identity,
35533560
);
35543561
}
35553562

@@ -3576,7 +3583,7 @@ export class TestState {
35763583
markerOrRange
35773584
);
35783585
// Write response JSON
3579-
return filesToSearch + baselineContent + JSON.stringify(highlights, undefined, 2);
3586+
return filesToSearch + baselineContent + (!highlights?.length ? JSON.stringify(highlights, undefined, 2) : "");
35803587
}
35813588

35823589
public verifyBaselineDocumentHighlights(markerOrRange: ArrayOrSingle<MarkerOrNameOrRange>, options: FourSlashInterface.VerifyDocumentHighlightsOptions | undefined) {

0 commit comments

Comments
 (0)