@@ -8,15 +8,15 @@ import Configuration from "../../configuration";
8
8
import * as html from "./html" ;
9
9
10
10
export class ResultSetPanelProvider implements WebviewViewProvider {
11
- _view : WebviewView | WebviewPanel ;
11
+ _view : WebviewView | WebviewPanel ;
12
12
loadingState : boolean ;
13
13
currentQuery : Query < any > ;
14
14
constructor ( ) {
15
15
this . _view = undefined ;
16
16
this . loadingState = false ;
17
17
}
18
18
19
- resolveWebviewView ( webviewView : WebviewView | WebviewPanel , context ?: WebviewViewResolveContext , _token ?: CancellationToken ) {
19
+ resolveWebviewView ( webviewView : WebviewView | WebviewPanel , context ?: WebviewViewResolveContext , _token ?: CancellationToken ) {
20
20
this . _view = webviewView ;
21
21
22
22
this . _view . onDidDispose ( ( ) => {
@@ -33,54 +33,65 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
33
33
34
34
webviewView . webview . html = html . getLoadingHTML ( ) ;
35
35
this . _view . webview . onDidReceiveMessage ( async ( message ) => {
36
- if ( message . query ) {
37
-
38
- if ( this . currentQuery ) {
39
- // If we get a request for a new query, then we need to close the old one
40
- if ( this . currentQuery . getId ( ) !== message . queryId ) {
41
- // This is a new query, so we need to clean up the old one
36
+ switch ( message . command ) {
37
+ case `cancel` :
38
+ commands . executeCommand ( `vscode-db2i.statement.cancel` ) ;
39
+ if ( this . currentQuery ) {
42
40
await this . currentQuery . close ( ) ;
43
- this . currentQuery = undefined ;
44
41
}
45
- }
46
-
47
- try {
48
- setCancelButtonVisibility ( true ) ;
49
- if ( this . currentQuery === undefined ) {
50
- // We will need to revisit this if we ever allow multiple result tabs like ACS does
51
- // Query.cleanup();
52
-
53
- let query = await JobManager . getPagingStatement ( message . query , { isClCommand : message . isCL , autoClose : true , isTerseResults : true } ) ;
54
- this . currentQuery = query ;
42
+ break ;
43
+
44
+ default :
45
+ if ( message . query ) {
46
+
47
+ if ( this . currentQuery ) {
48
+ // If we get a request for a new query, then we need to close the old one
49
+ if ( this . currentQuery . getId ( ) !== message . queryId ) {
50
+ // This is a new query, so we need to clean up the old one
51
+ await this . currentQuery . close ( ) ;
52
+ this . currentQuery = undefined ;
53
+ }
54
+ }
55
+
56
+ try {
57
+ setCancelButtonVisibility ( true ) ;
58
+ if ( this . currentQuery === undefined ) {
59
+ // We will need to revisit this if we ever allow multiple result tabs like ACS does
60
+ // Query.cleanup();
61
+
62
+ let query = await JobManager . getPagingStatement ( message . query , { isClCommand : message . isCL , autoClose : true , isTerseResults : true } ) ;
63
+ this . currentQuery = query ;
64
+ }
65
+
66
+ let queryResults = this . currentQuery . getState ( ) == QueryState . RUN_MORE_DATA_AVAILABLE ? await this . currentQuery . fetchMore ( ) : await this . currentQuery . run ( ) ;
67
+
68
+ const jobId = this . currentQuery . getHostJob ( ) . id ;
69
+
70
+ this . _view . webview . postMessage ( {
71
+ command : `rows` ,
72
+ jobId,
73
+ rows : queryResults . data ,
74
+ columnMetaData : queryResults . metadata ? queryResults . metadata . columns : undefined , // Query.fetchMore() doesn't return the metadata
75
+ columnHeadings : Configuration . get ( `resultsets.columnHeadings` ) || 'Name' ,
76
+ queryId : this . currentQuery . getId ( ) ,
77
+ update_count : queryResults . update_count ,
78
+ isDone : queryResults . is_done
79
+ } ) ;
80
+
81
+ } catch ( e ) {
82
+ this . setError ( e . message ) ;
83
+ this . _view . webview . postMessage ( {
84
+ command : `rows` ,
85
+ rows : [ ] ,
86
+ queryId : `` ,
87
+ isDone : true
88
+ } ) ;
89
+ }
90
+
91
+ setCancelButtonVisibility ( false ) ;
92
+ updateStatusBar ( ) ;
55
93
}
56
-
57
- let queryResults = this . currentQuery . getState ( ) == QueryState . RUN_MORE_DATA_AVAILABLE ? await this . currentQuery . fetchMore ( ) : await this . currentQuery . run ( ) ;
58
-
59
- const jobId = this . currentQuery . getHostJob ( ) . id ;
60
-
61
- this . _view . webview . postMessage ( {
62
- command : `rows` ,
63
- jobId,
64
- rows : queryResults . data ,
65
- columnMetaData : queryResults . metadata ? queryResults . metadata . columns : undefined , // Query.fetchMore() doesn't return the metadata
66
- columnHeadings : Configuration . get ( `resultsets.columnHeadings` ) || 'Name' ,
67
- queryId : this . currentQuery . getId ( ) ,
68
- update_count : queryResults . update_count ,
69
- isDone : queryResults . is_done
70
- } ) ;
71
-
72
- } catch ( e ) {
73
- this . setError ( e . message ) ;
74
- this . _view . webview . postMessage ( {
75
- command : `rows` ,
76
- rows : [ ] ,
77
- queryId : `` ,
78
- isDone : true
79
- } ) ;
80
- }
81
-
82
- setCancelButtonVisibility ( false ) ;
83
- updateStatusBar ( ) ;
94
+ break ;
84
95
}
85
96
} ) ;
86
97
}
@@ -92,11 +103,11 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
92
103
await delay ( 100 ) ;
93
104
currentLoop += 1 ;
94
105
}
95
-
106
+
96
107
if ( this . _view && 'show' in this . _view ) {
97
108
this . _view . show ( true ) ;
98
109
}
99
-
110
+
100
111
}
101
112
102
113
async focus ( ) {
@@ -132,11 +143,11 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
132
143
}
133
144
}
134
145
135
- async setScrolling ( basicSelect , isCL = false , queryId : string = `` ) {
146
+ async setScrolling ( basicSelect , isCL = false , queryId : string = `` , withCancel = false ) {
136
147
this . loadingState = false ;
137
148
await this . focus ( ) ;
138
149
139
- this . _view . webview . html = html . generateScroller ( basicSelect , isCL ) ;
150
+ this . _view . webview . html = html . generateScroller ( basicSelect , isCL , withCancel ) ;
140
151
141
152
this . _view . webview . postMessage ( {
142
153
command : `fetch` ,
0 commit comments