Skip to content

Commit 3a4bd7d

Browse files
Clean up code lens
1 parent be20b95 commit 3a4bd7d

3 files changed

Lines changed: 23 additions & 16 deletions

File tree

extensions/ql-vscode/src/CodeLensProvider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
CodeLensProvider,
33
TextDocument,
44
CodeLens,
5-
Command
5+
Command,
6+
Range
67
} from 'vscode';
78

89
class MyCodeLensProvider implements CodeLensProvider {
@@ -17,12 +18,16 @@ class MyCodeLensProvider implements CodeLensProvider {
1718
if (textLine.text.includes('predicate')) {
1819
const uri = document.uri;
1920
const regex = new RegExp(/predicate/);
20-
const args = textLine.text.search(regex);
21-
const range = textLine.range;
21+
const startIndex = textLine.text.search(regex);
22+
const range: Range = new Range(
23+
textLine.range.start.line, startIndex + 10,
24+
textLine.range.end.line, startIndex + 11
25+
);
26+
2227
const command: Command = {
2328
command: 'codeQL.codeLensQuickEval',
2429
title: 'CodeQL: Quick Evaluation',
25-
arguments: [uri, range, args]
30+
arguments: [uri, range]
2631
};
2732
const codeLens = new CodeLens(range, command);
2833
codeLenses.push(codeLens);

extensions/ql-vscode/src/extension.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
window as Window,
1313
env,
1414
window,
15-
QuickPickItem
15+
QuickPickItem,
16+
Range
1617
} from 'vscode';
1718
import { LanguageClient } from 'vscode-languageclient';
1819
import * as os from 'os';
@@ -476,9 +477,8 @@ async function activateWithInstalledDistribution(
476477
progress: ProgressCallback,
477478
token: CancellationToken,
478479
databaseItem: DatabaseItem | undefined,
479-
args?: any
480+
args?: Range
480481
): Promise<void> {
481-
// console.log('args', args);
482482
if (qs !== undefined) {
483483
// If no databaseItem is specified, use the database currently selected in the Databases UI
484484
databaseItem = databaseItem || await databaseUI.getDatabaseItem(progress, token);
@@ -493,6 +493,7 @@ async function activateWithInstalledDistribution(
493493
selectedQuery,
494494
progress,
495495
token,
496+
undefined,
496497
args
497498
);
498499
const item = qhm.buildCompletedQuery(info);
@@ -723,7 +724,7 @@ async function activateWithInstalledDistribution(
723724
progress: ProgressCallback,
724725
token: CancellationToken,
725726
uri: Uri | undefined,
726-
...args: any
727+
args: Range
727728
) => await compileAndRunQuery(true, uri, progress, token, undefined, args),
728729
{
729730
title: 'Running query',

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as tmp from 'tmp-promise';
55
import {
66
CancellationToken,
77
ConfigurationTarget,
8+
Range,
89
TextDocument,
910
TextEditor,
1011
Uri,
@@ -327,17 +328,17 @@ async function convertToQlPath(filePath: string): Promise<string> {
327328

328329

329330
/** Gets the selected position within the given editor. */
330-
async function getSelectedPosition(editor: TextEditor, args?: any): Promise<messages.Position> {
331-
const pos = args[0].start;
332-
const posEnd = args[0].end;
333-
const argsLength = args[1] + 10;
331+
async function getSelectedPosition(editor: TextEditor, args?: Range): Promise<messages.Position> {
332+
const range = args || editor.selection;
333+
const pos = range.start;
334+
const posEnd = range.end;
334335
// Convert from 0-based to 1-based line and column numbers.
335336
return {
336337
fileName: await convertToQlPath(editor.document.fileName),
337338
line: pos.line + 1,
338-
column: pos.character + argsLength,
339+
column: pos.character + 1,
339340
endLine: posEnd.line + 1,
340-
endColumn: posEnd.character - argsLength
341+
endColumn: posEnd.character + 1
341342
};
342343
}
343344

@@ -486,7 +487,7 @@ type SelectedQuery = {
486487
* @param selectedResourceUri The selected resource when the command was run.
487488
* @param quickEval Whether the command being run is `Quick Evaluation`.
488489
*/
489-
export async function determineSelectedQuery(selectedResourceUri: Uri | undefined, quickEval: boolean, args?: any): Promise<SelectedQuery> {
490+
export async function determineSelectedQuery(selectedResourceUri: Uri | undefined, quickEval: boolean, args?: Range): Promise<SelectedQuery> {
490491
const editor = window.activeTextEditor;
491492

492493
// Choose which QL file to use.
@@ -555,8 +556,8 @@ export async function compileAndRunQueryAgainstDatabase(
555556
selectedQueryUri: Uri | undefined,
556557
progress: ProgressCallback,
557558
token: CancellationToken,
558-
args?: any,
559559
templates?: messages.TemplateDefinitions,
560+
args?: Range
560561
): Promise<QueryWithResults> {
561562
if (!db.contents || !db.contents.dbSchemeUri) {
562563
throw new Error(`Database ${db.databaseUri} does not have a CodeQL database scheme.`);

0 commit comments

Comments
 (0)