Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Use col numbers from cmd outputs to give precise source locations for…
Browse files Browse the repository at this point in the history
… error/warnings (#1573)
  • Loading branch information
dhowden authored and ramya-rao-a committed Mar 15, 2018
1 parent 5eab209 commit 86d3f5a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ export function guessPackageNameFromFile(filePath): Promise<string[]> {
export interface ICheckResult {
file: string;
line: number;
col: number;
msg: string;
severity: string;
}
Expand Down Expand Up @@ -611,8 +612,9 @@ export function runTool(args: string[], cwd: string, severity: string, useStdErr
continue;
}
atleastSingleMatch = true;
let [_, __, file, ___, lineStr, ____, charStr, msg] = match;
let [_, __, file, ___, lineStr, ____, colStr, msg] = match;
let line = +lineStr;
let col = +colStr;

// Building skips vendor folders,
// But vet and lint take in directories and not import paths, so no way to skip them
Expand All @@ -622,7 +624,7 @@ export function runTool(args: string[], cwd: string, severity: string, useStdErr
}

file = path.resolve(cwd, file);
ret.push({ file, line, msg, severity });
ret.push({ file, line, col, msg, severity });
outputChannel.appendLine(`${file}:${line}: ${msg}`);
}
if (!atleastSingleMatch && unexpectedOutput && vscode.window.activeTextEditor) {
Expand All @@ -631,6 +633,7 @@ export function runTool(args: string[], cwd: string, severity: string, useStdErr
ret.push({
file: vscode.window.activeTextEditor.document.fileName,
line: 1,
col: 1,
msg: stderr,
severity: 'error'
});
Expand Down Expand Up @@ -663,7 +666,11 @@ export function handleDiagnosticErrors(document: vscode.TextDocument, errors: IC
let range = new vscode.Range(error.line - 1, 0, error.line - 1, document.lineAt(error.line - 1).range.end.character + 1);
let text = document.getText(range);
let [_, leading, trailing] = /^(\s*).*(\s*)$/.exec(text);
startColumn = leading.length;
if (error.col === 0) {
startColumn = leading.length;
} else {
startColumn = error.col - 1; // range is 0-indexed
}
endColumn = text.length - trailing.length;
}
let range = new vscode.Range(error.line - 1, startColumn, error.line - 1, endColumn);
Expand Down

0 comments on commit 86d3f5a

Please sign in to comment.