Skip to content

Commit 70748c6

Browse files
authored
fix: locate problems correctly when there are %INC statements (#1347) (#1448)
* fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347) * fix: locate problems correctly when there are %INC statements (#1347)
1 parent 13aa0be commit 70748c6

File tree

7 files changed

+365
-68
lines changed

7 files changed

+365
-68
lines changed

client/src/components/logViewer/ProblemProcessor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ function processRawLocationDesc(
537537
});
538538

539539
locations.map((location) => {
540-
location.lineNumber = lineNumber - offset.lineOffset;
540+
location.lineNumber = lineNumber;
541541
location.startColumn =
542542
location.startColumn - offset.columnOffset + columnCorrection;
543543
location.endColumn =
@@ -664,8 +664,7 @@ function processGeneralLocation(
664664
return null;
665665
}
666666

667-
const lineNumber =
668-
decomposeCodeLogLine(sourceCodeLines[0]).lineNumber - offset.lineOffset;
667+
const lineNumber = decomposeCodeLogLine(sourceCodeLines[0]).lineNumber;
669668
const wholeLine = sourceCodeLines.reduce(
670669
(accumulator, line) => accumulator + line.substring(offset.columnOffset),
671670
);

client/src/components/logViewer/logParser.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import {
99
isSourceCodeLineAfterLineWrapping,
1010
} from "./ProblemProcessor";
1111

12-
export function parseLog(logs: LogLine[], logStartFlag: string): Problem[] {
12+
export function parseLog(
13+
logs: LogLine[],
14+
logStartFlag: string,
15+
): [Problem[], string[]] {
1316
if (logs.length === 0 || logStartFlag.trim() === "") {
14-
return [];
17+
return [[], []];
1518
}
1619

1720
// logs cleaning
@@ -21,6 +24,7 @@ export function parseLog(logs: LogLine[], logStartFlag: string): Problem[] {
2124
let problemProcessor: ProblemProcessor = new ProblemProcessor();
2225
let offset: LocationOffset;
2326
const problems: Problem[] = [];
27+
const codeLines: string[] = [];
2428

2529
problemRelatedLogs.forEach((logLine) => {
2630
if (isProblemTypeLog(logLine)) {
@@ -42,6 +46,8 @@ export function parseLog(logs: LogLine[], logStartFlag: string): Problem[] {
4246
problemProcessor.appendProblemLogLine(logLine);
4347
return;
4448
} else {
49+
codeLines.push(logLine.line);
50+
4551
if (!isValidSourceCodeLog(logLine)) {
4652
return;
4753
}
@@ -79,7 +85,7 @@ export function parseLog(logs: LogLine[], logStartFlag: string): Problem[] {
7985

8086
problemProcessor = null;
8187

82-
return problems;
88+
return [problems, cleanCodeLines(codeLines)];
8389
}
8490

8591
function getTheLatestLogs(logs: LogLine[], firstCodeLine: string): LogLine[] {
@@ -184,3 +190,24 @@ function isValidSourceCodeLog(logLine: LogLine): boolean {
184190
function areSameLines(line1: string, line2: string) {
185191
return line1 === line2;
186192
}
193+
194+
// keep each line number only once
195+
function cleanCodeLines(codeLines: string[]): string[] {
196+
if (codeLines.length === 0) {
197+
return codeLines;
198+
}
199+
200+
let previousLineNumber = -1;
201+
const result = [];
202+
codeLines.forEach((line) => {
203+
const lineNumber = decomposeCodeLogLine(line)?.lineNumber ?? -1;
204+
if (lineNumber === previousLineNumber) {
205+
return;
206+
} else {
207+
previousLineNumber = lineNumber;
208+
result.push(line);
209+
}
210+
});
211+
212+
return result;
213+
}

client/src/components/logViewer/sasDiagnostics.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ async function updateDiagnostics(
7777
return;
7878
}
7979

80-
const problems = parseLog(logs, codeDoc.wrappedCodeLineAt(0));
80+
const [problems, codeLinesInLog] = parseLog(
81+
logs,
82+
codeDoc.wrappedCodeLineAt(0),
83+
);
8184

82-
updateProblemLocation(problems, codeDoc);
85+
await updateProblemLocation(problems, codeDoc, codeLinesInLog);
8386

8487
const problemsWithValidLocation = problems.filter((problem) => {
8588
const { lineNumber, startColumn, endColumn } = problem;
@@ -94,23 +97,30 @@ async function updateDiagnostics(
9497
);
9598
}
9699

97-
function updateProblemLocation(problems: Problem[], codeDoc: SASCodeDocument) {
98-
problems.forEach((problem) => {
100+
async function updateProblemLocation(
101+
problems: Problem[],
102+
codeDoc: SASCodeDocument,
103+
codeLinesInLog: string[],
104+
) {
105+
for (const problem of problems) {
99106
const { lineNumber, startColumn, endColumn } = problem;
100107
const {
101108
lineNumber: actualLineNumber,
102109
startColumn: actualStartColumn,
103110
endColumn: actualEndColumn,
104-
} = codeDoc.getLocationInRawCode({
105-
lineNumber,
106-
startColumn,
107-
endColumn,
108-
});
111+
} = await codeDoc.getLocationInRawCode(
112+
{
113+
lineNumber,
114+
startColumn,
115+
endColumn,
116+
},
117+
codeLinesInLog,
118+
);
109119

110120
problem.lineNumber = actualLineNumber;
111121
problem.startColumn = actualStartColumn;
112122
problem.endColumn = actualEndColumn;
113-
});
123+
}
114124
}
115125

116126
function constructDiagnostics(problems: Problem[]): Diagnostic[] {

0 commit comments

Comments
 (0)