@@ -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,13 @@ export async function executeQuery(
842875 const endTime = Date . now ( ) ;
843876 const duration = ( endTime - startTime ) . toString ( ) ;
844877
878+ if ( token ?. isCancellationRequested ) {
879+ return undefined ;
880+ }
881+
845882 // set context for root nodes
846883 if ( selectedConn instanceof InsightsConnection ) {
847- writeScratchpadResult (
884+ await writeScratchpadResult (
848885 results ,
849886 query ,
850887 connLabel ,
@@ -875,7 +912,7 @@ export async function executeQuery(
875912 await setUriContent ( uri , JSON . stringify ( plot ) ) ;
876913 }
877914 } else if ( ext . isResultsTabVisible ) {
878- writeQueryResultsToView (
915+ await writeQueryResultsToView (
879916 results ,
880917 query ,
881918 connLabel ,
@@ -888,7 +925,7 @@ export async function executeQuery(
888925 connVersion ,
889926 ) ;
890927 } else {
891- writeQueryResultsToConsole (
928+ await writeQueryResultsToConsole (
892929 results ,
893930 query ,
894931 connLabel ,
@@ -1123,7 +1160,7 @@ export async function exportConnections(connLabel?: string) {
11231160 }
11241161}
11251162
1126- export function writeQueryResultsToConsole (
1163+ export async function writeQueryResultsToConsole (
11271164 result : string | string [ ] ,
11281165 query : string ,
11291166 connLabel : string ,
@@ -1133,7 +1170,7 @@ export function writeQueryResultsToConsole(
11331170 isPython ?: boolean ,
11341171 duration ?: string ,
11351172 isFromConnTree ?: boolean ,
1136- ) : void {
1173+ ) : Promise < void > {
11371174 const queryConsole = ExecutionConsole . start ( ) ;
11381175 const isNonEmptyArray = Array . isArray ( result ) && result . length > 0 ;
11391176 const valueToDecode = isNonEmptyArray ? result [ 0 ] : result . toString ( ) ;
@@ -1169,7 +1206,7 @@ export function writeQueryResultsToConsole(
11691206 }
11701207}
11711208
1172- export function writeQueryResultsToView (
1209+ export async function writeQueryResultsToView (
11731210 result : any ,
11741211 query : string ,
11751212 connLabel : string ,
@@ -1180,8 +1217,8 @@ export function writeQueryResultsToView(
11801217 duration ?: string ,
11811218 isFromConnTree ?: boolean ,
11821219 connVersion ?: number ,
1183- ) : void {
1184- commands . executeCommand (
1220+ ) : Promise < void > {
1221+ await commands . executeCommand (
11851222 "kdb.resultsPanel.update" ,
11861223 result ,
11871224 isInsights ,
@@ -1204,7 +1241,7 @@ export function writeQueryResultsToView(
12041241 }
12051242}
12061243
1207- export function writeScratchpadResult (
1244+ export async function writeScratchpadResult (
12081245 result : ScratchpadResult ,
12091246 query : string ,
12101247 connLabel : string ,
@@ -1213,7 +1250,7 @@ export function writeScratchpadResult(
12131250 isWorkbook : boolean ,
12141251 duration : string ,
12151252 connVersion : number ,
1216- ) : void {
1253+ ) : Promise < void > {
12171254 let errorMsg ;
12181255
12191256 if ( result . error ) {
@@ -1226,7 +1263,7 @@ export function writeScratchpadResult(
12261263 }
12271264
12281265 if ( ext . isResultsTabVisible ) {
1229- writeQueryResultsToView (
1266+ await writeQueryResultsToView (
12301267 errorMsg ?? result ,
12311268 query ,
12321269 connLabel ,
@@ -1239,7 +1276,7 @@ export function writeScratchpadResult(
12391276 connVersion ,
12401277 ) ;
12411278 } else {
1242- writeQueryResultsToConsole (
1279+ await writeQueryResultsToConsole (
12431280 errorMsg ?? result . data ,
12441281 query ,
12451282 connLabel ,
0 commit comments