@@ -5,6 +5,7 @@ import * as tmp from 'tmp-promise';
55import {
66 CancellationToken ,
77 ConfigurationTarget ,
8+ Range ,
89 TextDocument ,
910 TextEditor ,
1011 Uri ,
@@ -327,17 +328,18 @@ async function convertToQlPath(filePath: string): Promise<string> {
327328
328329
329330/** 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+ } ;
341343}
342344
343345/**
@@ -485,7 +487,7 @@ type SelectedQuery = {
485487 * @param selectedResourceUri The selected resource when the command was run.
486488 * @param quickEval Whether the command being run is `Quick Evaluation`.
487489*/
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 > {
489491 const editor = window . activeTextEditor ;
490492
491493 // Choose which QL file to use.
@@ -539,7 +541,7 @@ export async function determineSelectedQuery(selectedResourceUri: Uri | undefine
539541 // Report an error if we end up in this (hopefully unlikely) situation.
540542 throw new Error ( 'The selected resource for quick evaluation should match the active editor.' ) ;
541543 }
542- quickEvalPosition = await getSelectedPosition ( editor ) ;
544+ quickEvalPosition = await getSelectedPosition ( editor , args ) ;
543545 quickEvalText = editor . document . getText ( editor . selection ) ;
544546 }
545547
@@ -555,13 +557,14 @@ export async function compileAndRunQueryAgainstDatabase(
555557 progress : ProgressCallback ,
556558 token : CancellationToken ,
557559 templates ?: messages . TemplateDefinitions ,
560+ args ?: Range
558561) : Promise < QueryWithResults > {
559562 if ( ! db . contents || ! db . contents . dbSchemeUri ) {
560563 throw new Error ( `Database ${ db . databaseUri } does not have a CodeQL database scheme.` ) ;
561564 }
562565
563566 // 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 ) ;
565568
566569 const historyItemOptions : QueryHistoryItemOptions = { } ;
567570 historyItemOptions . isQuickQuery === isQuickQueryPath ( queryPath ) ;
0 commit comments