forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickEvalCodeLensProvider.ts
43 lines (35 loc) · 1.31 KB
/
quickEvalCodeLensProvider.ts
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
import {
CodeLensProvider,
TextDocument,
CodeLens,
Command,
Range
} from 'vscode';
class QuickEvalCodeLensProvider implements CodeLensProvider {
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
const codeLenses: CodeLens[] = [];
for (let index = 0; index < document.lineCount; index++) {
const textLine = document.lineAt(index);
// Match a predicate signature, including predicate name, parameter list, and opening brace.
// This currently does not match predicates that span multiple lines.
const regex = new RegExp(/(\w+)\s*\([^()]*\)\s*\{/);
const matches = textLine.text.match(regex);
// Make sure that a code lens is not generated for any predicate that is commented out.
if (matches && !(/^\s*\/\//).test(textLine.text)) {
const range: Range = new Range(
textLine.range.start.line, matches.index!,
textLine.range.end.line, matches.index! + 1
);
const command: Command = {
command: 'codeQL.codeLensQuickEval',
title: `Quick Evaluation: ${matches[1]}`,
arguments: [document.uri, range]
};
const codeLens = new CodeLens(range, command);
codeLenses.push(codeLens);
}
}
return codeLenses;
}
}
export default QuickEvalCodeLensProvider;