@@ -6,6 +6,10 @@ const getInstance = require(`../../base`);
6
6
const Configuration = require ( `../../configuration` ) ;
7
7
const html = require ( `./html` ) ;
8
8
9
+ function delay ( t , v ) {
10
+ return new Promise ( resolve => setTimeout ( resolve , t , v ) ) ;
11
+ }
12
+
9
13
class ResultSetPanelProvider {
10
14
constructor ( ) {
11
15
/** @type {vscode.WebviewView } */
@@ -56,16 +60,25 @@ class ResultSetPanelProvider {
56
60
} ) ;
57
61
}
58
62
63
+ async ensureActivation ( ) {
64
+ let currentLoop = 0 ;
65
+ while ( ! this . _view && currentLoop < 15 ) {
66
+ await this . focus ( ) ;
67
+ await delay ( 100 ) ;
68
+ currentLoop += 1 ;
69
+ }
70
+ }
71
+
59
72
async focus ( ) {
60
73
if ( ! this . _view ) {
61
74
// Weird one. Kind of a hack. _view.show doesn't work yet because it's not initialized.
62
75
// But, we can call a VS Code API to focus on the tab, which then
63
76
// 1. calls resolveWebviewView
64
77
// 2. sets this._view
65
78
await vscode . commands . executeCommand ( `vscode-db2i.resultset.focus` ) ;
79
+ } else {
80
+ this . _view . show ( true ) ;
66
81
}
67
-
68
- this . _view . show ( true ) ;
69
82
}
70
83
71
84
async setLoadingText ( content ) {
@@ -112,7 +125,9 @@ exports.initialise = (context) => {
112
125
let resultSetProvider = new ResultSetPanelProvider ( ) ;
113
126
114
127
context . subscriptions . push (
115
- vscode . window . registerWebviewViewProvider ( `vscode-db2i.resultset` , resultSetProvider ) ,
128
+ vscode . window . registerWebviewViewProvider ( `vscode-db2i.resultset` , resultSetProvider , {
129
+ webviewOptions : { retainContextWhenHidden : true } ,
130
+ } ) ,
116
131
117
132
vscode . commands . registerCommand ( `vscode-db2i.runEditorStatement` ,
118
133
/**
@@ -129,6 +144,8 @@ exports.initialise = (context) => {
129
144
const editor = vscode . window . activeTextEditor ;
130
145
131
146
if ( optionsIsValid || ( editor && editor . document . languageId === `sql` ) ) {
147
+ await resultSetProvider . ensureActivation ( ) ;
148
+
132
149
/** @type {StatementInfo } */
133
150
const statement = ( optionsIsValid ? options : this . parseStatement ( editor ) ) ;
134
151
0 commit comments