-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodeActions.ts
More file actions
61 lines (51 loc) · 2.29 KB
/
Copy pathcodeActions.ts
File metadata and controls
61 lines (51 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as vscode from 'vscode';
export class CodeActionProvider implements vscode.CodeActionProvider {
provideCodeActions(
document: vscode.TextDocument,
range: vscode.Range,
context: vscode.CodeActionContext,
token: vscode.CancellationToken
): vscode.CodeAction[] {
const actions: vscode.CodeAction[] = [];
for (const diagnostic of context.diagnostics) {
var diagnosticCode = diagnostic.code;
if (typeof(diagnosticCode) === "object" && typeof(diagnosticCode) !== null) {
diagnosticCode = diagnosticCode.value;
}
// Set up one action for suppressing the specific warning on the line targeted by the diagnostic
const suppressAction = new vscode.CodeAction(
`Suppress warning for ${diagnosticCode} here`,
vscode.CodeActionKind.QuickFix
);
// 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
const suppressLineEdit = new vscode.WorkspaceEdit();
suppressLineEdit.insert(
document.uri,
new vscode.Position(
diagnostic.range.start.line,
0,
),
`${indent}// cppcheck-suppress ${diagnosticCode}\n`
);
suppressAction.edit = suppressLineEdit;
suppressAction.diagnostics = [diagnostic];
actions.push(suppressAction);
// Set up one action for suppressing warning of a given type universally
const suppressTypeAction = new vscode.CodeAction(
`Suppress warning type ${diagnosticCode} universally`,
vscode.CodeActionKind.QuickFix
);
suppressTypeAction.command = {
command: "cppcheck-official.suppressWarningAll",
title: "Suppress warning here",
arguments: [diagnostic]
};
suppressTypeAction.diagnostics = [diagnostic];
actions.push(suppressTypeAction);
}
return actions;
}
}