Skip to content

Commit be20b95

Browse files
Working code lens - needs improvement
1 parent c89a4be commit be20b95

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

extensions/ql-vscode/src/CodeLensProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class MyCodeLensProvider implements CodeLensProvider {
1515
for (let index = 0; index < document.lineCount; index++) {
1616
const textLine = document.lineAt(index);
1717
if (textLine.text.includes('predicate')) {
18-
// const regex = new RegExp(/predicate/);
19-
const args = textLine.text.search((new RegExp(/predicate/)));
20-
console.log(textLine, args);
18+
const uri = document.uri;
19+
const regex = new RegExp(/predicate/);
20+
const args = textLine.text.search(regex);
2121
const range = textLine.range;
2222
const command: Command = {
2323
command: 'codeQL.codeLensQuickEval',
2424
title: 'CodeQL: Quick Evaluation',
25-
arguments: ['argument', false]
25+
arguments: [uri, range, args]
2626
};
2727
const codeLens = new CodeLens(range, command);
2828
codeLenses.push(codeLens);

extensions/ql-vscode/src/extension.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ async function activateWithInstalledDistribution(
468468
forceReveal: WebviewReveal
469469
): Promise<void> {
470470
await intm.showResults(query, forceReveal, false);
471-
console.log(query.query.quickEvalPosition);
472471
}
473472

474473
async function compileAndRunQuery(
@@ -479,7 +478,7 @@ async function activateWithInstalledDistribution(
479478
databaseItem: DatabaseItem | undefined,
480479
args?: any
481480
): Promise<void> {
482-
console.log(args);
481+
// console.log('args', args);
483482
if (qs !== undefined) {
484483
// If no databaseItem is specified, use the database currently selected in the Databases UI
485484
databaseItem = databaseItem || await databaseUI.getDatabaseItem(progress, token);
@@ -717,13 +716,20 @@ async function activateWithInstalledDistribution(
717716
})
718717
);
719718

720-
commands.registerCommand('codeQL.codeLensQuickEval', async (
721-
progress: ProgressCallback,
722-
token: CancellationToken,
723-
uri: Uri | undefined,
724-
args: any) => {
725-
await compileAndRunQuery(true, uri, progress, token, undefined, args );
726-
});
719+
ctx.subscriptions.push(
720+
commandRunnerWithProgress(
721+
'codeQL.codeLensQuickEval',
722+
async (
723+
progress: ProgressCallback,
724+
token: CancellationToken,
725+
uri: Uri | undefined,
726+
...args: any
727+
) => await compileAndRunQuery(true, uri, progress, token, undefined, args),
728+
{
729+
title: 'Running query',
730+
cancellable: true
731+
})
732+
);
727733

728734
ctx.subscriptions.push(
729735
commandRunnerWithProgress('codeQL.quickQuery', async (

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,17 @@ async function convertToQlPath(filePath: string): Promise<string> {
327327

328328

329329
/** Gets the selected position within the given editor. */
330-
async function getSelectedPosition(editor: TextEditor, args: any | undefined): Promise<messages.Position> {
331-
const pos = editor.selection.start;
332-
const posEnd = editor.selection.end;
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;
333334
// Convert from 0-based to 1-based line and column numbers.
334335
return {
335336
fileName: await convertToQlPath(editor.document.fileName),
336337
line: pos.line + 1,
337-
column: pos.character + 1,
338+
column: pos.character + argsLength,
338339
endLine: posEnd.line + 1,
339-
endColumn: posEnd.character + 1
340+
endColumn: posEnd.character - argsLength
340341
};
341342
}
342343

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

491492
// Choose which QL file to use.
@@ -554,7 +555,7 @@ export async function compileAndRunQueryAgainstDatabase(
554555
selectedQueryUri: Uri | undefined,
555556
progress: ProgressCallback,
556557
token: CancellationToken,
557-
args: any | undefined,
558+
args?: any,
558559
templates?: messages.TemplateDefinitions,
559560
): Promise<QueryWithResults> {
560561
if (!db.contents || !db.contents.dbSchemeUri) {

0 commit comments

Comments
 (0)