Skip to content

Commit 7b61b56

Browse files
Make suggested changes
1 parent cdaf47d commit 7b61b56

3 files changed

Lines changed: 32 additions & 32 deletions

File tree

extensions/ql-vscode/src/CodeLensProvider.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Range
77
} from 'vscode';
88

9-
class MyCodeLensProvider implements CodeLensProvider {
9+
class QuickEvalCodeLensProvider implements CodeLensProvider {
1010
// Each provider requires a provideCodeLenses function which will give the various documents
1111
// the code lenses
1212
async provideCodeLenses(document: TextDocument): Promise<CodeLens[]> {
@@ -15,26 +15,26 @@ class MyCodeLensProvider implements CodeLensProvider {
1515

1616
for (let index = 0; index < document.lineCount; index++) {
1717
const textLine = document.lineAt(index);
18-
const regex = new RegExp(/(?=(\w+\(\s*.*(?:,\s*)*\)\s*\{))\1/g);
19-
if (textLine.text.match(regex)) {
20-
const uri = document.uri;
18+
// Match a predicate signature, including predicate name, parameter list, and opening brace.
19+
const regex = new RegExp(/\w+\(\s*.*(?:,\s*)*\)\s*\{/);
2120
const startIndex = textLine.text.search(regex);
22-
const range: Range = new Range(
23-
textLine.range.start.line, startIndex,
24-
textLine.range.end.line, startIndex - 1
25-
);
21+
if (startIndex !== -1) {
22+
const range: Range = new Range(
23+
textLine.range.start.line, startIndex,
24+
textLine.range.end.line, startIndex + 1
25+
);
2626

27-
const command: Command = {
28-
command: 'codeQL.codeLensQuickEval',
29-
title: 'CodeQL: Quick Evaluation',
30-
arguments: [uri, range]
31-
};
32-
const codeLens = new CodeLens(range, command);
33-
codeLenses.push(codeLens);
34-
}
27+
const command: Command = {
28+
command: 'codeQL.codeLensQuickEval',
29+
title: 'CodeQL: Quick Evaluation',
30+
arguments: [document.uri, range]
31+
};
32+
const codeLens = new CodeLens(range, command);
33+
codeLenses.push(codeLens);
3534
}
35+
}
3636
return codeLenses;
3737
}
3838
}
3939

40-
export default MyCodeLensProvider;
40+
export default QuickEvalCodeLensProvider;

extensions/ql-vscode/src/extension.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { testExplorerExtensionId, TestHub } from 'vscode-test-adapter-api';
2222

2323
import { AstViewer } from './astViewer';
2424
import * as archiveFilesystemProvider from './archive-filesystem-provider';
25-
import MyCodeLensProvider from './CodeLensProvider';
25+
import QuickEvalCodeLensProvider from './codeLensProvider';
2626
import { CodeQLCliServer, CliVersionConstraint } from './cli';
2727
import {
2828
CliConfigListener,
@@ -159,9 +159,9 @@ export interface CodeQLExtensionInterface {
159159
*/
160160
export async function activate(ctx: ExtensionContext): Promise<CodeQLExtensionInterface | Record<string, never>> {
161161

162-
const codelensProvider = new MyCodeLensProvider();
162+
const codelensProvider = new QuickEvalCodeLensProvider();
163163

164-
languages.registerCodeLensProvider('*', codelensProvider);
164+
languages.registerCodeLensProvider({ scheme: 'file', language: 'ql' }, codelensProvider);
165165

166166
void logger.log(`Starting ${extensionId} extension`);
167167
if (extension === undefined) {
@@ -478,7 +478,7 @@ async function activateWithInstalledDistribution(
478478
progress: ProgressCallback,
479479
token: CancellationToken,
480480
databaseItem: DatabaseItem | undefined,
481-
args?: Range
481+
range?: Range
482482
): Promise<void> {
483483
if (qs !== undefined) {
484484
// If no databaseItem is specified, use the database currently selected in the Databases UI
@@ -495,7 +495,7 @@ async function activateWithInstalledDistribution(
495495
progress,
496496
token,
497497
undefined,
498-
args
498+
range
499499
);
500500
const item = qhm.buildCompletedQuery(info);
501501
await showResultsForCompletedQuery(item, WebviewReveal.NotForced);
@@ -751,8 +751,8 @@ async function activateWithInstalledDistribution(
751751
progress: ProgressCallback,
752752
token: CancellationToken,
753753
uri: Uri | undefined,
754-
args: Range
755-
) => await compileAndRunQuery(true, uri, progress, token, undefined, args),
754+
range: Range
755+
) => await compileAndRunQuery(true, uri, progress, token, undefined, range),
756756
{
757757
title: 'Running query',
758758
cancellable: true

extensions/ql-vscode/src/run-queries.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ async function convertToQlPath(filePath: string): Promise<string> {
333333

334334

335335
/** Gets the selected position within the given editor. */
336-
async function getSelectedPosition(editor: TextEditor, args?: Range): Promise<messages.Position> {
337-
const range = args || editor.selection;
338-
const pos = range.start;
339-
const posEnd = range.end;
336+
async function getSelectedPosition(editor: TextEditor, range?: Range): Promise<messages.Position> {
337+
const selectedRange = range || editor.selection;
338+
const pos = selectedRange.start;
339+
const posEnd = selectedRange.end;
340340
// Convert from 0-based to 1-based line and column numbers.
341341
return {
342342
fileName: await convertToQlPath(editor.document.fileName),
@@ -492,7 +492,7 @@ type SelectedQuery = {
492492
* @param selectedResourceUri The selected resource when the command was run.
493493
* @param quickEval Whether the command being run is `Quick Evaluation`.
494494
*/
495-
export async function determineSelectedQuery(selectedResourceUri: Uri | undefined, quickEval: boolean, args?: Range): Promise<SelectedQuery> {
495+
export async function determineSelectedQuery(selectedResourceUri: Uri | undefined, quickEval: boolean, range?: Range): Promise<SelectedQuery> {
496496
const editor = window.activeTextEditor;
497497

498498
// Choose which QL file to use.
@@ -546,7 +546,7 @@ export async function determineSelectedQuery(selectedResourceUri: Uri | undefine
546546
// Report an error if we end up in this (hopefully unlikely) situation.
547547
throw new Error('The selected resource for quick evaluation should match the active editor.');
548548
}
549-
quickEvalPosition = await getSelectedPosition(editor, args);
549+
quickEvalPosition = await getSelectedPosition(editor, range);
550550
quickEvalText = editor.document.getText(editor.selection);
551551
}
552552

@@ -562,14 +562,14 @@ export async function compileAndRunQueryAgainstDatabase(
562562
progress: ProgressCallback,
563563
token: CancellationToken,
564564
templates?: messages.TemplateDefinitions,
565-
args?: Range
565+
range?: Range
566566
): Promise<QueryWithResults> {
567567
if (!db.contents || !db.contents.dbSchemeUri) {
568568
throw new Error(`Database ${db.databaseUri} does not have a CodeQL database scheme.`);
569569
}
570570

571571
// Determine which query to run, based on the selection and the active editor.
572-
const { queryPath, quickEvalPosition, quickEvalText } = await determineSelectedQuery(selectedQueryUri, quickEval, args);
572+
const { queryPath, quickEvalPosition, quickEvalText } = await determineSelectedQuery(selectedQueryUri, quickEval, range);
573573

574574
const historyItemOptions: QueryHistoryItemOptions = {};
575575
historyItemOptions.isQuickQuery === isQuickQueryPath(queryPath);

0 commit comments

Comments
 (0)