@@ -4,6 +4,8 @@ import * as path from 'path';
44import * as tmp from 'tmp' ;
55import { promisify } from 'util' ;
66import * as vscode from 'vscode' ;
7+ import { ErrorCodes , ResponseError } from 'vscode-languageclient' ;
8+
79import * as cli from './cli' ;
810import { DatabaseItem , getUpgradesDirectories } from './databases' ;
911import * as helpers from './helpers' ;
@@ -103,13 +105,19 @@ export class QueryInfo {
103105 } finally {
104106 qs . unRegisterCallback ( callbackId ) ;
105107 }
106- return result || { evaluationTime : 0 , message : "No result from server" , queryId : - 1 , runId : callbackId , resultType : messages . QueryResultType . OTHER_ERROR } ;
108+ return result || {
109+ evaluationTime : 0 ,
110+ message : "No result from server" ,
111+ queryId : - 1 ,
112+ runId : callbackId ,
113+ resultType : messages . QueryResultType . OTHER_ERROR
114+ } ;
107115 }
108116
109117 async compile (
110118 qs : qsClient . QueryServerClient ,
111119 ) : Promise < messages . CompilationMessage [ ] > {
112- let compiled : messages . CheckQueryResult ;
120+ let compiled : messages . CheckQueryResult | undefined ;
113121 try {
114122 const params : messages . CompileQueryParams = {
115123 compilationOptions : {
@@ -140,8 +148,7 @@ export class QueryInfo {
140148 } finally {
141149 qs . logger . log ( " - - - COMPILATION DONE - - - " ) ;
142150 }
143-
144- return ( compiled . messages || [ ] ) . filter ( msg => msg . severity == 0 ) ;
151+ return ( compiled ?. messages || [ ] ) . filter ( msg => msg . severity === messages . Severity . ERROR ) ;
145152 }
146153
147154 /**
@@ -411,7 +418,16 @@ export async function compileAndRunQueryAgainstDatabase(
411418 const query = new QueryInfo ( qlProgram , db , packConfig . dbscheme , quickEvalPosition , metadata ) ;
412419 await checkDbschemeCompatibility ( cliServer , qs , query ) ;
413420
414- const errors = await query . compile ( qs ) ;
421+ let errors ;
422+ try {
423+ errors = await query . compile ( qs ) ;
424+ } catch ( e ) {
425+ if ( e instanceof ResponseError && e . code == ErrorCodes . RequestCancelled ) {
426+ return createSyntheticResult ( query , db , historyItemOptions , 'Query cancelled' ) ;
427+ } else {
428+ throw e ;
429+ }
430+ }
415431
416432 if ( errors . length == 0 ) {
417433 const result = await query . run ( qs ) ;
@@ -453,20 +469,30 @@ export async function compileAndRunQueryAgainstDatabase(
453469 " and choose CodeQL Query Server from the dropdown." ) ;
454470 }
455471
456- return {
457- query,
458- result : {
459- evaluationTime : 0 ,
460- resultType : messages . QueryResultType . OTHER_ERROR ,
461- queryId : - 1 ,
462- runId : - 1 ,
463- message : "Query had compilation errors"
464- } ,
465- database : {
466- name : db . name ,
467- databaseUri : db . databaseUri . toString ( true )
468- } ,
469- options : historyItemOptions ,
470- } ;
472+ return createSyntheticResult ( query , db , historyItemOptions , 'Query had compilation errors' ) ;
471473 }
472474}
475+
476+ function createSyntheticResult (
477+ query : QueryInfo ,
478+ db : DatabaseItem ,
479+ historyItemOptions : QueryHistoryItemOptions ,
480+ message : string
481+ ) {
482+
483+ return {
484+ query,
485+ result : {
486+ evaluationTime : 0 ,
487+ resultType : messages . QueryResultType . CANCELLATION ,
488+ queryId : - 1 ,
489+ runId : - 1 ,
490+ message
491+ } ,
492+ database : {
493+ name : db . name ,
494+ databaseUri : db . databaseUri . toString ( true )
495+ } ,
496+ options : historyItemOptions ,
497+ } ;
498+ }
0 commit comments