Skip to content

Commit 5c0e055

Browse files
committed
optimize problem matcher
1 parent 31c8be2 commit 5c0e055

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

src/ProblemMatcher.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ function toVscServerity(str_: string): vscode.DiagnosticSeverity {
8686
}
8787
}
8888

89-
function newVscFilePosition(toolchain: ToolchainName, line: number, col?: number): vscode.Position {
90-
if (col != undefined && col < 0)
91-
col = 0;
92-
switch (toolchain) {
93-
default:
94-
return new vscode.Position(line > 0 ? (line - 1) : 0, col || 0);
95-
}
89+
function newVscFileRange(line: number, start: number, len: number): vscode.Range {
90+
if (start < 0)
91+
start = 0;
92+
if (len < 0)
93+
len = 0;
94+
const _line = line > 0 ? (line - 1) : 0;
95+
return new vscode.Range(
96+
new vscode.Position(_line, start),
97+
new vscode.Position(_line, start + len));
9698
}
9799

98100
//////////////////////////////////////////////////////////////////////
@@ -128,8 +130,8 @@ export function parseArmccCompilerLog(projApi: ProjectBaseApi, logFile: File): C
128130
const diags = result[fspath] || [];
129131
if (result[fspath] == undefined) result[fspath] = diags;
130132

131-
const pos = newVscFilePosition(projApi.toolchainName(), line, 0);
132-
const vscDiag = new vscode.Diagnostic(new vscode.Range(pos, pos), message, toVscServerity(severity));
133+
const vscDiag = new vscode.Diagnostic(
134+
newVscFileRange(line, 0, 10), message, toVscServerity(severity));
133135
vscDiag.code = errCode;
134136
vscDiag.source = 'armcc';
135137
diags.push(vscDiag);
@@ -185,9 +187,8 @@ export function parseSdccCompilerLog(projApi: ProjectBaseApi, logfile: File): Co
185187
const diags = result[fspath] || [];
186188
if (result[fspath] == undefined) result[fspath] = diags;
187189

188-
const pos = newVscFilePosition(projApi.toolchainName(), line, col);
189190
const vscDiag = new vscode.Diagnostic(
190-
new vscode.Range(pos, pos), `${severity}: ${message}`, toVscServerity(severity));
191+
newVscFileRange(line, col || 0, 10), `${severity}: ${message}`, toVscServerity(severity));
191192
vscDiag.source = 'sdcc';
192193
vscDiag.code = errCode;
193194
diags.push(vscDiag);
@@ -255,8 +256,8 @@ export function parseGccCompilerLog(projApi: ProjectBaseApi, logfile: File): Com
255256
const diags = result[fspath] || [];
256257
if (result[fspath] == undefined) result[fspath] = diags;
257258

258-
const pos = newVscFilePosition(projApi.toolchainName(), line, col);
259-
const vscDiag = new vscode.Diagnostic(new vscode.Range(pos, pos), message, toVscServerity(severity));
259+
const vscDiag = new vscode.Diagnostic(
260+
newVscFileRange(line, col, 10), message, toVscServerity(severity));
260261
vscDiag.source = problemSource;
261262
vscDiag.code = errCode;
262263
diags.push(vscDiag);
@@ -296,8 +297,8 @@ export function parseKeilc51CompilerLog(projApi: ProjectBaseApi, logfile: File):
296297
const diags = result[fspath] || [];
297298
if (result[fspath] == undefined) result[fspath] = diags;
298299

299-
const pos = newVscFilePosition(projApi.toolchainName(), line, 0);
300-
const vscDiag = new vscode.Diagnostic(new vscode.Range(pos, pos), message, toVscServerity(severity));
300+
const vscDiag = new vscode.Diagnostic(
301+
newVscFileRange(line, 0, 10), message, toVscServerity(severity));
301302
vscDiag.source = 'Keil_C51';
302303
vscDiag.code = code;
303304
diags.push(vscDiag);
@@ -347,8 +348,8 @@ export function parseIarCompilerLog(projApi: ProjectBaseApi, logfile: File): Com
347348
const diags = result[fspath] || [];
348349
if (result[fspath] == undefined) result[fspath] = diags;
349350

350-
const pos = newVscFilePosition(projApi.toolchainName(), line, 0);
351-
const vscDiag = new vscode.Diagnostic(new vscode.Range(pos, pos), message, toVscServerity(severity));
351+
const vscDiag = new vscode.Diagnostic(
352+
newVscFileRange(line, 0, 10), message, toVscServerity(severity));
352353
vscDiag.code = errCode;
353354
vscDiag.source = projApi.toolchainName() == 'IAR_STM8' ? 'iccstm8' : 'iccarm';
354355
diags.push(vscDiag);
@@ -408,9 +409,8 @@ export function parseCosmicStm8CompilerLog(projApi: ProjectBaseApi, logfile: Fil
408409
const diags = result[fspath] || [];
409410
if (result[fspath] == undefined) result[fspath] = diags;
410411

411-
const pos_s = newVscFilePosition(projApi.toolchainName(), line, column);
412-
const pos_e = newVscFilePosition(projApi.toolchainName(), line, column + column_rng);
413-
const vscDiag = new vscode.Diagnostic(new vscode.Range(pos_s, pos_e), message, toVscServerity(severity));
412+
const vscDiag = new vscode.Diagnostic(
413+
newVscFileRange(line, column, column_rng), message, toVscServerity(severity));
414414
vscDiag.source = toolname;
415415

416416
diags.push(vscDiag);

0 commit comments

Comments
 (0)