@@ -5,6 +5,7 @@ import * as tmp from 'tmp-promise';
5
5
import {
6
6
CancellationToken ,
7
7
ConfigurationTarget ,
8
+ Range ,
8
9
TextDocument ,
9
10
TextEditor ,
10
11
Uri ,
@@ -327,17 +328,18 @@ async function convertToQlPath(filePath: string): Promise<string> {
327
328
328
329
329
330
/** Gets the selected position within the given editor. */
330
- async function getSelectedPosition ( editor : TextEditor ) : Promise < messages . Position > {
331
- const pos = editor . selection . start ;
332
- const posEnd = editor . selection . end ;
333
- // Convert from 0-based to 1-based line and column numbers.
334
- return {
335
- fileName : await convertToQlPath ( editor . document . fileName ) ,
336
- line : pos . line + 1 ,
337
- column : pos . character + 1 ,
338
- endLine : posEnd . line + 1 ,
339
- endColumn : posEnd . character + 1
340
- } ;
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 ;
335
+ // Convert from 0-based to 1-based line and column numbers.
336
+ return {
337
+ fileName : await convertToQlPath ( editor . document . fileName ) ,
338
+ line : pos . line + 1 ,
339
+ column : pos . character + 1 ,
340
+ endLine : posEnd . line + 1 ,
341
+ endColumn : posEnd . character + 1
342
+ } ;
341
343
}
342
344
343
345
/**
@@ -485,7 +487,7 @@ type SelectedQuery = {
485
487
* @param selectedResourceUri The selected resource when the command was run.
486
488
* @param quickEval Whether the command being run is `Quick Evaluation`.
487
489
*/
488
- export async function determineSelectedQuery ( selectedResourceUri : Uri | undefined , quickEval : boolean ) : Promise < SelectedQuery > {
490
+ export async function determineSelectedQuery ( selectedResourceUri : Uri | undefined , quickEval : boolean , args ?: Range ) : Promise < SelectedQuery > {
489
491
const editor = window . activeTextEditor ;
490
492
491
493
// Choose which QL file to use.
@@ -539,7 +541,7 @@ export async function determineSelectedQuery(selectedResourceUri: Uri | undefine
539
541
// Report an error if we end up in this (hopefully unlikely) situation.
540
542
throw new Error ( 'The selected resource for quick evaluation should match the active editor.' ) ;
541
543
}
542
- quickEvalPosition = await getSelectedPosition ( editor ) ;
544
+ quickEvalPosition = await getSelectedPosition ( editor , args ) ;
543
545
quickEvalText = editor . document . getText ( editor . selection ) ;
544
546
}
545
547
@@ -555,13 +557,14 @@ export async function compileAndRunQueryAgainstDatabase(
555
557
progress : ProgressCallback ,
556
558
token : CancellationToken ,
557
559
templates ?: messages . TemplateDefinitions ,
560
+ args ?: Range
558
561
) : Promise < QueryWithResults > {
559
562
if ( ! db . contents || ! db . contents . dbSchemeUri ) {
560
563
throw new Error ( `Database ${ db . databaseUri } does not have a CodeQL database scheme.` ) ;
561
564
}
562
565
563
566
// Determine which query to run, based on the selection and the active editor.
564
- const { queryPath, quickEvalPosition, quickEvalText } = await determineSelectedQuery ( selectedQueryUri , quickEval ) ;
567
+ const { queryPath, quickEvalPosition, quickEvalText } = await determineSelectedQuery ( selectedQueryUri , quickEval , args ) ;
565
568
566
569
const historyItemOptions : QueryHistoryItemOptions = { } ;
567
570
historyItemOptions . isQuickQuery === isQuickQueryPath ( queryPath ) ;
0 commit comments