Skip to content

Commit bdf8c0b

Browse files
committed
Add setting to enable/disable Quick Eval codelens
1 parent bc08cbe commit bdf8c0b

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [UNRELEASED]
44

5+
- Add a setting to enable/disable the Quick Evaluation CodeLens. [#1052](https://github.com/github/vscode-codeql/pull/1052)
56
- Avoid creating a third column when opening the results view. The results view will always open to the right of the active editor, unless the active editor is in the rightmost editor column. In that case open in the leftmost column. [#1037](https://github.com/github/vscode-codeql/pull/1037)
67
- Add a CodeLens to make the Quick Evaluation command more accessible. Click the `Quick Evaluation` prompt above a predicate definition in the editor to evaluate that predicate on its own. [#1035](https://github.com/github/vscode-codeql/pull/1035)
78
- Fix a bug where the _Alerts_ option would show in the results view even if there is no alerts table available. [#1038](https://github.com/github/vscode-codeql/pull/1038)

extensions/ql-vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@
206206
"default": null,
207207
"description": "Path to a directory where the CodeQL extension should store query server logs. If empty, the extension stores logs in a temporary workspace folder and deletes the contents after each run."
208208
},
209+
"codeQL.runningQueries.quickEvalCodelens": {
210+
"type": "boolean",
211+
"default": true,
212+
"description": "Enable the 'Quick Evaluation' CodeLens."
213+
},
209214
"codeQL.resultsDisplay.pageSize": {
210215
"type": "integer",
211216
"default": 200,

extensions/ql-vscode/src/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ export class CliConfigListener extends ConfigListener implements CliConfig {
275275
}
276276
}
277277

278+
/**
279+
* Whether to enable CodeLens for the 'Quick Evaluation' command.
280+
*/
281+
const QUICK_EVAL_CODELENS_SETTING = new Setting('quickEvalCodelens', RUNNING_QUERIES_SETTING);
282+
283+
export function isQuickEvalCodelensEnabled() {
284+
return QUICK_EVAL_CODELENS_SETTING.getValue<boolean>();
285+
}
286+
287+
278288
// Enable experimental features
279289

280290
/**
Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
import {
22
CodeLensProvider,
33
TextDocument,
4-
CodeLens,
4+
CodeLens,
55
Command,
66
Range
77
} from 'vscode';
8-
8+
import { isQuickEvalCodelensEnabled } from './config';
9+
910
class QuickEvalCodeLensProvider implements CodeLensProvider {
1011
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
1112

1213
const codeLenses: CodeLens[] = [];
1314

14-
for (let index = 0; index < document.lineCount; index++) {
15-
const textLine = document.lineAt(index);
16-
17-
// Match a predicate signature, including predicate name, parameter list, and opening brace.
18-
// This currently does not match predicates that span multiple lines.
19-
const regex = new RegExp(/(\w+)\s*\([^()]*\)\s*\{/);
20-
21-
const matches = textLine.text.match(regex);
22-
23-
// Make sure that a code lens is not generated for any predicate that is commented out.
24-
if (matches && !(/^\s*\/\//).test(textLine.text)) {
25-
const range: Range = new Range(
26-
textLine.range.start.line, matches.index!,
27-
textLine.range.end.line, matches.index! + 1
28-
);
29-
30-
const command: Command = {
31-
command: 'codeQL.codeLensQuickEval',
32-
title: `Quick Evaluation: ${matches[1]}`,
33-
arguments: [document.uri, range]
34-
};
35-
const codeLens = new CodeLens(range, command);
36-
codeLenses.push(codeLens);
15+
if (isQuickEvalCodelensEnabled()) {
16+
for (let index = 0; index < document.lineCount; index++) {
17+
const textLine = document.lineAt(index);
18+
19+
// Match a predicate signature, including predicate name, parameter list, and opening brace.
20+
// This currently does not match predicates that span multiple lines.
21+
const regex = new RegExp(/(\w+)\s*\([^()]*\)\s*\{/);
22+
23+
const matches = textLine.text.match(regex);
24+
25+
// Make sure that a code lens is not generated for any predicate that is commented out.
26+
if (matches && !(/^\s*\/\//).test(textLine.text)) {
27+
const range: Range = new Range(
28+
textLine.range.start.line, matches.index!,
29+
textLine.range.end.line, matches.index! + 1
30+
);
31+
32+
const command: Command = {
33+
command: 'codeQL.codeLensQuickEval',
34+
title: `Quick Evaluation: ${matches[1]}`,
35+
arguments: [document.uri, range]
36+
};
37+
const codeLens = new CodeLens(range, command);
38+
codeLenses.push(codeLens);
39+
}
3740
}
3841
}
3942
return codeLenses;
4043
}
4144
}
42-
43-
export default QuickEvalCodeLensProvider;
45+
46+
export default QuickEvalCodeLensProvider;

0 commit comments

Comments
 (0)