Skip to content
Open
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
13 changes: 7 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const criticalWarningTypes = [
'preprocessorErrorDirective',
'syntaxError',
'unhandledChar',
'unknownMacro'
'unknownMacro',
'checkersReport'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just weird to put checkersReport in "criticalWarningTypes" because it's not critical

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am skeptic that users wants to see the checkersReport typically. maybe it could be optional.

];

function parseSeverity(str: string): vscode.DiagnosticSeverity {
Expand Down Expand Up @@ -270,19 +271,19 @@ async function runCppcheckOnFileXML(
for (const e of errors) {
const isCriticalError = criticalWarningTypes.includes(e.$.id);
const locations = e.location || [];
if (!locations.length) {
if (!isCriticalError && !locations.length) {
continue;
}

const mainLoc = locations[locations.length - 1].$;
const mainLoc = locations.length ? locations[locations.length - 1]?.$ : [];

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

// Cppcheck line number is 1-indexed, while VS Code uses 0-indexing
let line = Number(mainLoc.line) - 1;
let line = Number(mainLoc?.line ?? 0) - 1;
// Invalid line number usually means non-analysis output
if (isNaN(line) || line < 0 || line >= document.lineCount) {
if (isCriticalError) {
Expand All @@ -293,7 +294,7 @@ async function runCppcheckOnFileXML(
}

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