Add setting to enable/disable Quick Eval codelens

This commit is contained in:
shati-patel
2021-12-16 12:40:46 +00:00
committed by Shati Patel
parent bc08cbe74f
commit bdf8c0b9c2
4 changed files with 42 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
## [UNRELEASED]
- Add a setting to enable/disable the Quick Evaluation CodeLens. [#1052](https://github.com/github/vscode-codeql/pull/1052)
- 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)
- 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)
- 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)

View File

@@ -206,6 +206,11 @@
"default": null,
"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."
},
"codeQL.runningQueries.quickEvalCodelens": {
"type": "boolean",
"default": true,
"description": "Enable the 'Quick Evaluation' CodeLens."
},
"codeQL.resultsDisplay.pageSize": {
"type": "integer",
"default": 200,

View File

@@ -275,6 +275,16 @@ export class CliConfigListener extends ConfigListener implements CliConfig {
}
}
/**
* Whether to enable CodeLens for the 'Quick Evaluation' command.
*/
const QUICK_EVAL_CODELENS_SETTING = new Setting('quickEvalCodelens', RUNNING_QUERIES_SETTING);
export function isQuickEvalCodelensEnabled() {
return QUICK_EVAL_CODELENS_SETTING.getValue<boolean>();
}
// Enable experimental features
/**

View File

@@ -1,43 +1,46 @@
import {
CodeLensProvider,
TextDocument,
CodeLens,
CodeLens,
Command,
Range
} from 'vscode';
import { isQuickEvalCodelensEnabled } from './config';
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);
if (isQuickEvalCodelensEnabled()) {
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*\{/);
// 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);
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
);
// 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);
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;
export default QuickEvalCodeLensProvider;