Skip to content

Commit 537cd60

Browse files
authored
Truncate long files in fourslash baselines around +- n lines (#53769)
1 parent adcc39d commit 537cd60

File tree

283 files changed

+4750
-38900
lines changed

Some content is hidden

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

283 files changed

+4750
-38900
lines changed

src/harness/fourslashImpl.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ export class TestState {
14161416
return fileBaselines.join("\n\n");
14171417
}
14181418

1419+
private static readonly nLinesContext = 4;
1420+
14191421
private getBaselineContentForFile<T extends ts.DocumentSpan>(
14201422
fileName: string,
14211423
content: string,
@@ -1433,7 +1435,8 @@ export class TestState {
14331435
}: BaselineDocumentSpansWithFileContentsOptions<T>,
14341436
spanToContextId: Map<T, number>,
14351437
) {
1436-
let newContent = `=== ${fileName} ===\n`;
1438+
let readableContents = `// === ${fileName} ===`;
1439+
let newContent = "";
14371440
interface Detail {
14381441
location: number;
14391442
locationMarker: string;
@@ -1514,6 +1517,8 @@ export class TestState {
15141517
}
15151518
});
15161519
}
1520+
const lineStarts = ts.computeLineStarts(content);
1521+
let posLineInfo: { pos: number, line: number } | undefined;
15171522
// Our preferred way to write marker is
15181523
// /*MARKER*/[| some text |]
15191524
// [| some /*MARKER*/ text |]
@@ -1537,7 +1542,7 @@ export class TestState {
15371542
// Defer writing marker position to deffered marker index
15381543
if (deferredMarkerIndex !== undefined) return;
15391544
}
1540-
newContent += content.slice(pos, location);
1545+
textWithContext(location, type);
15411546
pos = location;
15421547
// Prefix
15431548
const prefix = detailPrefixes.get(detail);
@@ -1587,8 +1592,36 @@ export class TestState {
15871592
const suffix = detailSuffixes.get(detail);
15881593
if (suffix) newContent += suffix;
15891594
});
1590-
newContent += content.slice(pos);
1591-
return readableJsoncBaseline(newContent);
1595+
textWithContext(/*location*/ undefined, /*type*/ undefined);
1596+
return readableContents + (newContent ? "\n" + readableJsoncBaseline(newContent) : "");
1597+
1598+
function textWithContext(location: number | undefined, type: Detail["type"]) {
1599+
if (!newContent && location === undefined) ts.Debug.fail("Unsupported");
1600+
if (type !== "textEnd" && type !== "contextEnd") {
1601+
// Calculate pos to location number of lines
1602+
const posLine = posLineInfo?.pos === pos ? posLineInfo.line : ts.computeLineOfPosition(lineStarts, pos, posLineInfo?.line);
1603+
const locationLine = location !== undefined ? ts.computeLineOfPosition(lineStarts, location, posLine) : lineStarts.length - 1;
1604+
if (location !== undefined) posLineInfo = { pos: location, line: locationLine };
1605+
let nLines = 0;
1606+
if (newContent) nLines += TestState.nLinesContext + 1;
1607+
if (location !== undefined) nLines += TestState.nLinesContext + 1;
1608+
// first nLinesContext and last nLinesContext
1609+
if (locationLine - posLine > nLines) {
1610+
if (newContent) {
1611+
readableContents = readableContents + "\n" + readableJsoncBaseline(newContent + content.slice(pos, lineStarts[posLine + TestState.nLinesContext]) +
1612+
`--- (line: ${posLine + TestState.nLinesContext + 1}) skipped ---`);
1613+
if (location !== undefined) readableContents += "\n";
1614+
newContent = "";
1615+
}
1616+
if (location !== undefined) {
1617+
newContent += `--- (line: ${locationLine - TestState.nLinesContext + 1}) skipped ---\n` +
1618+
content.slice(lineStarts[locationLine - TestState.nLinesContext + 1], location);
1619+
}
1620+
return;
1621+
}
1622+
}
1623+
newContent += content.slice(pos, location);
1624+
}
15921625
}
15931626

15941627
private assertObjectsEqual<T>(fullActual: T, fullExpected: T, msgPrefix = ""): void {

tests/baselines/reference/cancellationWhenfindingAllRefsOnDefinition.baseline.jsonc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// === findAllReferences ===
22
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
3-
// export class Test{
4-
//
5-
// constructor(){
3+
// --- (line: 3) skipped ---
64
//
75
// }
86
//
@@ -24,9 +22,7 @@
2422

2523
// === Definitions ===
2624
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
27-
// export class Test{
28-
//
29-
// constructor(){
25+
// --- (line: 3) skipped ---
3026
//
3127
// }
3228
//
@@ -108,9 +104,7 @@
108104

109105
// === findAllReferences ===
110106
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
111-
// export class Test{
112-
//
113-
// constructor(){
107+
// --- (line: 3) skipped ---
114108
//
115109
// }
116110
//
@@ -132,9 +126,7 @@
132126

133127
// === Definitions ===
134128
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
135-
// export class Test{
136-
//
137-
// constructor(){
129+
// --- (line: 3) skipped ---
138130
//
139131
// }
140132
//

tests/baselines/reference/declarationMapGoToDefinition.baseline.jsonc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
// otherMethod() {
77
// if (Math.random() > 0.5) {
88
// return {x: 42};
9-
// }
10-
// return {y: "yes"};
11-
// }
12-
// }
13-
//
14-
// export interface SomeType {
15-
// member: number;
16-
// }
9+
// --- (line: 7) skipped ---
1710

1811
// === /tests/cases/fourslash/server/mymodule.ts ===
1912
// import * as mod from "./indexdef";

tests/baselines/reference/declarationMapsEnableMapping_NoInline.baseline.jsonc

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
// otherMethod() {
77
// if (Math.random() > 0.5) {
88
// return {x: 42};
9-
// }
10-
// return {y: "yes"};
11-
// }
12-
// }
13-
//
14-
// export interface SomeType {
15-
// member: number;
16-
// }
9+
// --- (line: 7) skipped ---
1710

1811
// === /mymodule.ts ===
1912
// import * as mod from "/dist/index";
@@ -32,14 +25,7 @@
3225

3326
// === goToType ===
3427
// === /index.ts ===
35-
// export class Foo {
36-
// member: string;
37-
// methodName(propName: SomeType): SomeType { return propName; }
38-
// otherMethod() {
39-
// if (Math.random() > 0.5) {
40-
// return {x: 42};
41-
// }
42-
// return {y: "yes"};
28+
// --- (line: 8) skipped ---
4329
// }
4430
// }
4531
//
@@ -72,14 +58,7 @@
7258
// otherMethod() {
7359
// if (Math.random() > 0.5) {
7460
// return {x: 42};
75-
// }
76-
// return {y: "yes"};
77-
// }
78-
// }
79-
//
80-
// export interface SomeType {
81-
// member: number;
82-
// }
61+
// --- (line: 7) skipped ---
8362

8463
// === /mymodule.ts ===
8564
// import * as mod from "/dist/index";
@@ -106,14 +85,7 @@
10685
// otherMethod() {
10786
// if (Math.random() > 0.5) {
10887
// return {x: 42};
109-
// }
110-
// return {y: "yes"};
111-
// }
112-
// }
113-
//
114-
// export interface SomeType {
115-
// member: number;
116-
// }
88+
// --- (line: 7) skipped ---
11789

11890
// === /mymodule.ts ===
11991
// import * as mod from "/dist/index";

tests/baselines/reference/declarationMapsEnableMapping_NoInlineSources.baseline.jsonc

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
// otherMethod() {
77
// if (Math.random() > 0.5) {
88
// return {x: 42};
9-
// }
10-
// return {y: "yes"};
11-
// }
12-
// }
13-
//
14-
// export interface SomeType {
15-
// member: number;
16-
// }
9+
// --- (line: 7) skipped ---
1710

1811
// === /mymodule.ts ===
1912
// import * as mod from "/dist/index";
@@ -32,14 +25,7 @@
3225

3326
// === goToType ===
3427
// === /index.ts ===
35-
// export class Foo {
36-
// member: string;
37-
// methodName(propName: SomeType): SomeType { return propName; }
38-
// otherMethod() {
39-
// if (Math.random() > 0.5) {
40-
// return {x: 42};
41-
// }
42-
// return {y: "yes"};
28+
// --- (line: 8) skipped ---
4329
// }
4430
// }
4531
//
@@ -72,14 +58,7 @@
7258
// otherMethod() {
7359
// if (Math.random() > 0.5) {
7460
// return {x: 42};
75-
// }
76-
// return {y: "yes"};
77-
// }
78-
// }
79-
//
80-
// export interface SomeType {
81-
// member: number;
82-
// }
61+
// --- (line: 7) skipped ---
8362

8463
// === /mymodule.ts ===
8564
// import * as mod from "/dist/index";
@@ -106,14 +85,7 @@
10685
// otherMethod() {
10786
// if (Math.random() > 0.5) {
10887
// return {x: 42};
109-
// }
110-
// return {y: "yes"};
111-
// }
112-
// }
113-
//
114-
// export interface SomeType {
115-
// member: number;
116-
// }
88+
// --- (line: 7) skipped ---
11789

11890
// === /mymodule.ts ===
11991
// import * as mod from "/dist/index";

tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping.baseline.jsonc

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
// otherMethod() {
77
// if (Math.random() > 0.5) {
88
// return {x: 42};
9-
// }
10-
// return {y: "yes"};
11-
// }
12-
// }
13-
//
14-
// export interface SomeType {
15-
// member: number;
16-
// }
9+
// --- (line: 7) skipped ---
1710

1811
// === /mymodule.ts ===
1912
// import * as mod from "/dist/index";
@@ -32,14 +25,7 @@
3225

3326
// === goToType ===
3427
// === /index.ts ===
35-
// export class Foo {
36-
// member: string;
37-
// methodName(propName: SomeType): SomeType { return propName; }
38-
// otherMethod() {
39-
// if (Math.random() > 0.5) {
40-
// return {x: 42};
41-
// }
42-
// return {y: "yes"};
28+
// --- (line: 8) skipped ---
4329
// }
4430
// }
4531
//
@@ -72,14 +58,7 @@
7258
// otherMethod() {
7359
// if (Math.random() > 0.5) {
7460
// return {x: 42};
75-
// }
76-
// return {y: "yes"};
77-
// }
78-
// }
79-
//
80-
// export interface SomeType {
81-
// member: number;
82-
// }
61+
// --- (line: 7) skipped ---
8362

8463
// === /mymodule.ts ===
8564
// import * as mod from "/dist/index";
@@ -106,14 +85,7 @@
10685
// otherMethod() {
10786
// if (Math.random() > 0.5) {
10887
// return {x: 42};
109-
// }
110-
// return {y: "yes"};
111-
// }
112-
// }
113-
//
114-
// export interface SomeType {
115-
// member: number;
116-
// }
88+
// --- (line: 7) skipped ---
11789

11890
// === /mymodule.ts ===
11991
// import * as mod from "/dist/index";

tests/baselines/reference/declarationMapsGeneratedMapsEnableMapping2.baseline.jsonc

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
// otherMethod() {
77
// if (Math.random() > 0.5) {
88
// return {x: 42};
9-
// }
10-
// return {y: "yes"};
11-
// }
12-
// }
13-
//
14-
// export interface SomeType {
15-
// member: number;
16-
// }
9+
// --- (line: 7) skipped ---
1710

1811
// === /mymodule.ts ===
1912
// import * as mod from "/dist/index";
@@ -32,14 +25,7 @@
3225

3326
// === goToType ===
3427
// === /index.ts ===
35-
// export class Foo {
36-
// member: string;
37-
// methodName(propName: SomeType): SomeType { return propName; }
38-
// otherMethod() {
39-
// if (Math.random() > 0.5) {
40-
// return {x: 42};
41-
// }
42-
// return {y: "yes"};
28+
// --- (line: 8) skipped ---
4329
// }
4430
// }
4531
//
@@ -72,14 +58,7 @@
7258
// otherMethod() {
7359
// if (Math.random() > 0.5) {
7460
// return {x: 42};
75-
// }
76-
// return {y: "yes"};
77-
// }
78-
// }
79-
//
80-
// export interface SomeType {
81-
// member: number;
82-
// }
61+
// --- (line: 7) skipped ---
8362

8463
// === /mymodule.ts ===
8564
// import * as mod from "/dist/index";
@@ -106,14 +85,7 @@
10685
// otherMethod() {
10786
// if (Math.random() > 0.5) {
10887
// return {x: 42};
109-
// }
110-
// return {y: "yes"};
111-
// }
112-
// }
113-
//
114-
// export interface SomeType {
115-
// member: number;
116-
// }
88+
// --- (line: 7) skipped ---
11789

11890
// === /mymodule.ts ===
11991
// import * as mod from "/dist/index";

0 commit comments

Comments
 (0)