Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,8 @@ export class TestState {
return fileBaselines.join("\n\n");
}

private static readonly nLinesContext = 4;

private getBaselineContentForFile<T extends ts.DocumentSpan>(
fileName: string,
content: string,
Expand All @@ -1433,7 +1435,8 @@ export class TestState {
}: BaselineDocumentSpansWithFileContentsOptions<T>,
spanToContextId: Map<T, number>,
) {
let newContent = `=== ${fileName} ===\n`;
let readableContents = `// === ${fileName} ===`;
let newContent = "";
interface Detail {
location: number;
locationMarker: string;
Expand Down Expand Up @@ -1514,6 +1517,8 @@ export class TestState {
}
});
}
const lineStarts = ts.computeLineStarts(content);
let posLineInfo: { pos: number, line: number } | undefined;
// Our preferred way to write marker is
// /*MARKER*/[| some text |]
// [| some /*MARKER*/ text |]
Expand All @@ -1537,7 +1542,7 @@ export class TestState {
// Defer writing marker position to deffered marker index
if (deferredMarkerIndex !== undefined) return;
}
newContent += content.slice(pos, location);
textWithContext(location, type);
pos = location;
// Prefix
const prefix = detailPrefixes.get(detail);
Expand Down Expand Up @@ -1587,8 +1592,36 @@ export class TestState {
const suffix = detailSuffixes.get(detail);
if (suffix) newContent += suffix;
});
newContent += content.slice(pos);
return readableJsoncBaseline(newContent);
textWithContext(/*location*/ undefined, /*type*/ undefined);
return readableContents + (newContent ? "\n" + readableJsoncBaseline(newContent) : "");

function textWithContext(location: number | undefined, type: Detail["type"]) {
if (!newContent && location === undefined) ts.Debug.fail("Unsupported");
if (type !== "textEnd" && type !== "contextEnd") {
// Calculate pos to location number of lines
const posLine = posLineInfo?.pos === pos ? posLineInfo.line : ts.computeLineOfPosition(lineStarts, pos, posLineInfo?.line);
const locationLine = location !== undefined ? ts.computeLineOfPosition(lineStarts, location, posLine) : lineStarts.length - 1;
if (location !== undefined) posLineInfo = { pos: location, line: locationLine };
let nLines = 0;
if (newContent) nLines += TestState.nLinesContext + 1;
if (location !== undefined) nLines += TestState.nLinesContext + 1;
// first nLinesContext and last nLinesContext
if (locationLine - posLine > nLines) {
if (newContent) {
readableContents = readableContents + "\n" + readableJsoncBaseline(newContent + content.slice(pos, lineStarts[posLine + TestState.nLinesContext]) +
`--- (line: ${posLine + TestState.nLinesContext + 1}) skipped ---`);
if (location !== undefined) readableContents += "\n";
newContent = "";
}
if (location !== undefined) {
newContent += `--- (line: ${locationLine - TestState.nLinesContext + 1}) skipped ---\n` +
content.slice(lineStarts[locationLine - TestState.nLinesContext + 1], location);
}
return;
}
}
newContent += content.slice(pos, location);
}
}

private assertObjectsEqual<T>(fullActual: T, fullExpected: T, msgPrefix = ""): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// === findAllReferences ===
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
// export class Test{
//
// constructor(){
// --- (line: 3) skipped ---
//
// }
//
Expand All @@ -24,9 +22,7 @@

// === Definitions ===
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
// export class Test{
//
// constructor(){
// --- (line: 3) skipped ---
//
// }
//
Expand Down Expand Up @@ -108,9 +104,7 @@

// === findAllReferences ===
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
// export class Test{
//
// constructor(){
// --- (line: 3) skipped ---
//
// }
//
Expand All @@ -132,9 +126,7 @@

// === Definitions ===
// === /tests/cases/fourslash/findAllRefsOnDefinition-import.ts ===
// export class Test{
//
// constructor(){
// --- (line: 3) skipped ---
//
// }
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /tests/cases/fourslash/server/mymodule.ts ===
// import * as mod from "./indexdef";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

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

// === goToType ===
// === /index.ts ===
// export class Foo {
// member: string;
// methodName(propName: SomeType): SomeType { return propName; }
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// --- (line: 8) skipped ---
// }
// }
//
Expand Down Expand Up @@ -72,14 +58,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand All @@ -106,14 +85,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

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

// === goToType ===
// === /index.ts ===
// export class Foo {
// member: string;
// methodName(propName: SomeType): SomeType { return propName; }
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// --- (line: 8) skipped ---
// }
// }
//
Expand Down Expand Up @@ -72,14 +58,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand All @@ -106,14 +85,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

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

// === goToType ===
// === /index.ts ===
// export class Foo {
// member: string;
// methodName(propName: SomeType): SomeType { return propName; }
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// --- (line: 8) skipped ---
// }
// }
//
Expand Down Expand Up @@ -72,14 +58,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand All @@ -106,14 +85,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

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

// === goToType ===
// === /index.ts ===
// export class Foo {
// member: string;
// methodName(propName: SomeType): SomeType { return propName; }
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// --- (line: 8) skipped ---
// }
// }
//
Expand Down Expand Up @@ -72,14 +58,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand All @@ -106,14 +85,7 @@
// otherMethod() {
// if (Math.random() > 0.5) {
// return {x: 42};
// }
// return {y: "yes"};
// }
// }
//
// export interface SomeType {
// member: number;
// }
// --- (line: 7) skipped ---

// === /mymodule.ts ===
// import * as mod from "/dist/index";
Expand Down
Loading