Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,32 @@ async function runCppcheckOnFileXML(
continue;
}

// Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
const mainLoc = locations[locations.length - 1].$;

// If main location is not current file, then skip displaying warning
if (!filePath.endsWith(mainLoc.file)) {
continue;
}

// Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
const line = Number(mainLoc.line) - 1;
// Invalid line number usually means non-analysis output
if (isNaN(line) || line < 0 || line >= document.lineCount) {
continue;
}

// Cppcheck col number is 1-indexed, while VS Code uses 0-indexing
let col = Number(mainLoc.column) - 1;
if (isNaN(col) || col < 0 || col > document.lineAt(line).text.length) {
col = 0;
}

const severity = parseSeverity(e.$.severity);
if (severityToNumber(severity) < minSevNum) {
continue;
}

const range = new vscode.Range(line, 0, line, document.lineAt(line).text.length);
const range = new vscode.Range(line, col, line, document.lineAt(line).text.length);
const diagnostic = new vscode.Diagnostic(range, e.$.msg, severity);
diagnostic.source = "cppcheck";
diagnostic.code = e.$.id;
Expand Down