Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to enable/disable Quick Eval codelens #1052

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [UNRELEASED]

- Add a setting to enable/disable the Quick Evaluation CodeLens. [#1052](https://github.com/github/vscode-codeql/pull/1052)
shati-patel marked this conversation as resolved.
Show resolved Hide resolved
- 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)
Expand Down
5 changes: 5 additions & 0 deletions extensions/ql-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
shati-patel marked this conversation as resolved.
Show resolved Hide resolved
"description": "Enable the 'Quick Evaluation' CodeLens."
},
"codeQL.resultsDisplay.pageSize": {
"type": "integer",
"default": 200,
Expand Down
10 changes: 10 additions & 0 deletions extensions/ql-vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
57 changes: 30 additions & 27 deletions extensions/ql-vscode/src/quickEvalCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -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);

// 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);
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*\{/);

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;

export default QuickEvalCodeLensProvider;