1
- import vscode , { SnippetString , ViewColumn , TreeView } from "vscode"
1
+ import vscode , { SnippetString , ViewColumn , TreeView , window } from "vscode"
2
2
3
3
import * as csv from "csv/sync" ;
4
4
@@ -57,8 +57,8 @@ export function initialise(context: vscode.ExtensionContext) {
57
57
webviewOptions : { retainContextWhenHidden : true } ,
58
58
} ) ,
59
59
60
- vscode . commands . registerCommand ( `vscode-db2i.statement.cancel` , async ( ) => {
61
- const selected = JobManager . getSelection ( ) ;
60
+ vscode . commands . registerCommand ( `vscode-db2i.statement.cancel` , async ( jobName ?: string ) => {
61
+ const selected = typeof jobName === `string` ? JobManager . getJob ( jobName ) : JobManager . getSelection ( ) ;
62
62
if ( selected ) {
63
63
updateStatusBar ( { canceling : true } ) ;
64
64
const cancelled = await selected . job . requestCancel ( ) ;
@@ -141,11 +141,16 @@ export function initialise(context: vscode.ExtensionContext) {
141
141
142
142
vscode . commands . registerCommand ( `vscode-db2i.editorExplain.withRun` , ( options ?: StatementInfo ) => { runHandler ( { qualifier : `explain` , ...options } ) } ) ,
143
143
vscode . commands . registerCommand ( `vscode-db2i.editorExplain.withoutRun` , ( options ?: StatementInfo ) => { runHandler ( { qualifier : `onlyexplain` , ...options } ) } ) ,
144
+ vscode . commands . registerCommand ( `vscode-db2i.runEditorStatement.inView` , ( options ?: StatementInfo ) => { runHandler ( { viewColumn : ViewColumn . Beside , ...options } ) } ) ,
144
145
vscode . commands . registerCommand ( `vscode-db2i.runEditorStatement` , ( options ?: StatementInfo ) => { runHandler ( options ) } )
145
146
)
146
147
}
147
148
148
149
async function runHandler ( options ?: StatementInfo ) {
150
+ if ( options === undefined || options . viewColumn === undefined ) {
151
+ await resultSetProvider . ensureActivation ( ) ;
152
+ }
153
+
149
154
// Options here can be a vscode.Uri when called from editor context.
150
155
// But that isn't valid here.
151
156
const optionsIsValid = ( options ?. content !== undefined ) ;
@@ -154,7 +159,13 @@ async function runHandler(options?: StatementInfo) {
154
159
vscode . commands . executeCommand ( 'vscode-db2i.dove.close' ) ;
155
160
156
161
if ( optionsIsValid || ( editor && editor . document . languageId === `sql` ) ) {
157
- await resultSetProvider . ensureActivation ( ) ;
162
+ let chosenView = resultSetProvider ;
163
+
164
+ const useWindow = ( title : string , column ?: ViewColumn ) => {
165
+ const webview = window . createWebviewPanel ( `sqlResultSet` , title , column || ViewColumn . Two , { retainContextWhenHidden : true , enableScripts : true , enableFindWidget : true } ) ;
166
+ chosenView = new ResultSetPanelProvider ( ) ;
167
+ chosenView . resolveWebviewView ( webview ) ;
168
+ }
158
169
159
170
const statementDetail = parseStatement ( editor , optionsIsValid ? options : undefined ) ;
160
171
@@ -178,10 +189,15 @@ async function runHandler(options?: StatementInfo) {
178
189
}
179
190
180
191
const statement = statementDetail . statement ;
192
+ const refs = statement . getObjectReferences ( ) ;
193
+ const ref = refs [ 0 ] ;
194
+
195
+ let possibleTitle = `SQL Results` ;
196
+ if ( ref && ref . object . name ) {
197
+ possibleTitle = ( ref . object . schema ? ref . object . schema + `.` : `` ) + ref . object . name ;
198
+ }
181
199
182
200
if ( statement . type === StatementType . Create || statement . type === StatementType . Alter ) {
183
- const refs = statement . getObjectReferences ( ) ;
184
- const ref = refs [ 0 ] ;
185
201
const databaseObj =
186
202
statement . type === StatementType . Create && ref . createType . toUpperCase ( ) === `schema`
187
203
? ref . object . schema || ``
@@ -191,29 +207,38 @@ async function runHandler(options?: StatementInfo) {
191
207
192
208
if ( statementDetail . content . trim ( ) . length > 0 ) {
193
209
try {
210
+ const inWindow = Boolean ( options && options . viewColumn ) ;
211
+
194
212
if ( statementDetail . qualifier === `cl` ) {
195
- resultSetProvider . setScrolling ( statementDetail . content , true ) ; // Never errors
213
+ if ( inWindow ) {
214
+ useWindow ( `CL results` , options . viewColumn ) ;
215
+ }
216
+ chosenView . setScrolling ( statementDetail . content , true ) ; // Never errors
217
+
196
218
} else if ( statementDetail . qualifier === `statement` ) {
197
219
// If it's a basic statement, we can let it scroll!
198
- resultSetProvider . setScrolling ( statementDetail . content ) ; // Never errors
220
+ if ( inWindow ) {
221
+ useWindow ( possibleTitle , options . viewColumn ) ;
222
+ }
223
+ chosenView . setScrolling ( statementDetail . content , false , undefined , inWindow ) ; // Never errors
199
224
200
225
} else if ( [ `explain` , `onlyexplain` ] . includes ( statementDetail . qualifier ) ) {
201
226
// If it's an explain, we need to
202
227
const selectedJob = JobManager . getSelection ( ) ;
203
228
if ( selectedJob ) {
204
229
const onlyExplain = statementDetail . qualifier === `onlyexplain` ;
205
230
206
- resultSetProvider . setLoadingText ( onlyExplain ? `Explaining without running...` : `Explaining...` ) ;
231
+ chosenView . setLoadingText ( onlyExplain ? `Explaining without running...` : `Explaining...` ) ;
207
232
const explainType : ExplainType = onlyExplain ? ExplainType . DoNotRun : ExplainType . Run ;
208
233
209
234
setCancelButtonVisibility ( true ) ;
210
235
const explained = await selectedJob . job . explain ( statementDetail . content , explainType ) ; // Can throw
211
236
setCancelButtonVisibility ( false ) ;
212
237
213
238
if ( onlyExplain ) {
214
- resultSetProvider . setLoadingText ( `Explained.` , false ) ;
239
+ chosenView . setLoadingText ( `Explained.` , false ) ;
215
240
} else {
216
- resultSetProvider . setScrolling ( statementDetail . content , false , explained . id ) ; // Never errors
241
+ chosenView . setScrolling ( statementDetail . content , false , explained . id ) ; // Never errors
217
242
}
218
243
219
244
explainTree = new ExplainTree ( explained . vedata ) ;
@@ -226,7 +251,7 @@ async function runHandler(options?: StatementInfo) {
226
251
}
227
252
} else {
228
253
// Otherwise... it's a bit complicated.
229
- resultSetProvider . setLoadingText ( `Executing SQL statement...` , false ) ;
254
+ chosenView . setLoadingText ( `Executing SQL statement...` , false ) ;
230
255
231
256
setCancelButtonVisibility ( true ) ;
232
257
updateStatusBar ( { executing : true } ) ;
@@ -279,13 +304,13 @@ async function runHandler(options?: StatementInfo) {
279
304
280
305
const textDoc = await vscode . workspace . openTextDocument ( { language : statementDetail . qualifier , content } ) ;
281
306
await vscode . window . showTextDocument ( textDoc ) ;
282
- resultSetProvider . setLoadingText ( `Query executed with ${ data . length } rows returned.` , false ) ;
307
+ chosenView . setLoadingText ( `Query executed with ${ data . length } rows returned.` , false ) ;
283
308
break ;
284
309
}
285
310
286
311
} else {
287
312
vscode . window . showInformationMessage ( `Statement executed with no data returned.` ) ;
288
- resultSetProvider . setLoadingText ( `Statement executed with no data returned.` ) ;
313
+ chosenView . setLoadingText ( `Statement executed with no data returned.` ) ;
289
314
}
290
315
}
291
316
@@ -304,7 +329,7 @@ async function runHandler(options?: StatementInfo) {
304
329
}
305
330
306
331
if ( [ `statement` , `explain` , `onlyexplain` ] . includes ( statementDetail . qualifier ) && statementDetail . history !== false ) {
307
- resultSetProvider . setError ( errorText ) ;
332
+ chosenView . setError ( errorText ) ;
308
333
} else {
309
334
vscode . window . showErrorMessage ( errorText ) ;
310
335
}
0 commit comments