Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,11 @@ async function runCppcheckOnFileXML(
} : e.$.id;

// If warning has a symbol we keep track of it
if (e.symbol?.[0]) {
diagnosticMetadataStore.set(diagnostic, {symbolName: e.symbol?.[0]});
}
const symbolName = e.symbol?.[0] ?? '';
// Save line of code at main location if we can access it
const mainLocLine = mainLocDocument?.lineAt(line)?.text ?? '';

diagnosticMetadataStore.set(diagnostic, {symbolName, mainLocLine});

// Related Information
const relatedInfos: vscode.DiagnosticRelatedInformation[] = [];
Expand Down
10 changes: 9 additions & 1 deletion src/util/codeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
continue;
}

const mainLocLineNumber = diagnostic.range.start.line;
const lineText = document.lineAt(mainLocLineNumber).text;
const expectedLineText = this.metadataStore.get(diagnostic)?.mainLocLine;

// If document has been edited so that diagnostic no longer refers to the correct line we don't provide code actions
if (lineText !== expectedLineText) {
continue;
}

var diagnosticCode = diagnostic.code;
if (typeof(diagnosticCode) === "object" && typeof(diagnosticCode) !== null) {
diagnosticCode = diagnosticCode.value;
Expand All @@ -33,7 +42,6 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
);

// Copy indentation from line affected by diagnostic
const lineText = document.lineAt(diagnostic.range.start.line).text;
const indent = lineText.match(/^\s*/)?.[0] ?? "";

// Insert suppression comment above affected line
Expand Down
1 change: 1 addition & 0 deletions src/util/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';

interface DiagnosticMetadata {
symbolName?: string;
mainLocLine?: string;
}

export class DiagnosticMetadataStore {
Expand Down
Loading