@@ -15,7 +15,9 @@ import { readFileSync } from "fs-extra";
1515import { join } from "path" ;
1616import * as url from "url" ;
1717import {
18+ CancellationToken ,
1819 Position ,
20+ ProgressLocation ,
1921 Range ,
2022 Uri ,
2123 ViewColumn ,
@@ -790,6 +792,37 @@ export async function executeQuery(
790792 isPython : boolean ,
791793 isWorkbook : boolean ,
792794 isFromConnTree ?: boolean ,
795+ ) : Promise < void > {
796+ await window . withProgress (
797+ {
798+ cancellable : true ,
799+ location : ProgressLocation . Window ,
800+ title : `Executing query (${ executorName } )` ,
801+ } ,
802+ async ( _progress , token ) => {
803+ await _executeQuery (
804+ query ,
805+ connLabel ,
806+ executorName ,
807+ context ,
808+ isPython ,
809+ isWorkbook ,
810+ isFromConnTree ,
811+ token ,
812+ ) ;
813+ } ,
814+ ) ;
815+ }
816+
817+ async function _executeQuery (
818+ query : string ,
819+ connLabel : string ,
820+ executorName : string ,
821+ context : string ,
822+ isPython : boolean ,
823+ isWorkbook : boolean ,
824+ isFromConnTree ?: boolean ,
825+ token ?: CancellationToken ,
793826) : Promise < void > {
794827 const connMngService = new ConnectionManagementService ( ) ;
795828 const queryConsole = ExecutionConsole . start ( ) ;
@@ -842,9 +875,14 @@ export async function executeQuery(
842875 const endTime = Date . now ( ) ;
843876 const duration = ( endTime - startTime ) . toString ( ) ;
844877
878+ /* istanbul ignore next */
879+ if ( token ?. isCancellationRequested ) {
880+ return undefined ;
881+ }
882+
845883 // set context for root nodes
846884 if ( selectedConn instanceof InsightsConnection ) {
847- writeScratchpadResult (
885+ await writeScratchpadResult (
848886 results ,
849887 query ,
850888 connLabel ,
@@ -875,7 +913,7 @@ export async function executeQuery(
875913 await setUriContent ( uri , JSON . stringify ( plot ) ) ;
876914 }
877915 } else if ( ext . isResultsTabVisible ) {
878- writeQueryResultsToView (
916+ await writeQueryResultsToView (
879917 results ,
880918 query ,
881919 connLabel ,
@@ -888,7 +926,7 @@ export async function executeQuery(
888926 connVersion ,
889927 ) ;
890928 } else {
891- writeQueryResultsToConsole (
929+ await writeQueryResultsToConsole (
892930 results ,
893931 query ,
894932 connLabel ,
@@ -1123,7 +1161,7 @@ export async function exportConnections(connLabel?: string) {
11231161 }
11241162}
11251163
1126- export function writeQueryResultsToConsole (
1164+ export async function writeQueryResultsToConsole (
11271165 result : string | string [ ] ,
11281166 query : string ,
11291167 connLabel : string ,
@@ -1133,7 +1171,7 @@ export function writeQueryResultsToConsole(
11331171 isPython ?: boolean ,
11341172 duration ?: string ,
11351173 isFromConnTree ?: boolean ,
1136- ) : void {
1174+ ) : Promise < void > {
11371175 const queryConsole = ExecutionConsole . start ( ) ;
11381176 const isNonEmptyArray = Array . isArray ( result ) && result . length > 0 ;
11391177 const valueToDecode = isNonEmptyArray ? result [ 0 ] : result . toString ( ) ;
@@ -1169,7 +1207,7 @@ export function writeQueryResultsToConsole(
11691207 }
11701208}
11711209
1172- export function writeQueryResultsToView (
1210+ export async function writeQueryResultsToView (
11731211 result : any ,
11741212 query : string ,
11751213 connLabel : string ,
@@ -1180,8 +1218,8 @@ export function writeQueryResultsToView(
11801218 duration ?: string ,
11811219 isFromConnTree ?: boolean ,
11821220 connVersion ?: number ,
1183- ) : void {
1184- commands . executeCommand (
1221+ ) : Promise < void > {
1222+ await commands . executeCommand (
11851223 "kdb.resultsPanel.update" ,
11861224 result ,
11871225 isInsights ,
@@ -1204,7 +1242,7 @@ export function writeQueryResultsToView(
12041242 }
12051243}
12061244
1207- export function writeScratchpadResult (
1245+ export async function writeScratchpadResult (
12081246 result : ScratchpadResult ,
12091247 query : string ,
12101248 connLabel : string ,
@@ -1213,7 +1251,7 @@ export function writeScratchpadResult(
12131251 isWorkbook : boolean ,
12141252 duration : string ,
12151253 connVersion : number ,
1216- ) : void {
1254+ ) : Promise < void > {
12171255 let errorMsg ;
12181256
12191257 if ( result . error ) {
@@ -1226,7 +1264,7 @@ export function writeScratchpadResult(
12261264 }
12271265
12281266 if ( ext . isResultsTabVisible ) {
1229- writeQueryResultsToView (
1267+ await writeQueryResultsToView (
12301268 errorMsg ?? result ,
12311269 query ,
12321270 connLabel ,
@@ -1239,7 +1277,7 @@ export function writeScratchpadResult(
12391277 connVersion ,
12401278 ) ;
12411279 } else {
1242- writeQueryResultsToConsole (
1280+ await writeQueryResultsToConsole (
12431281 errorMsg ?? result . data ,
12441282 query ,
12451283 connLabel ,
0 commit comments