Skip to content

Commit 5c19b41

Browse files
committed
Fix issue with ensuring the webview is activated
Signed-off-by: Liam Barry Allan <[email protected]>
1 parent 6ede425 commit 5c19b41

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"url": "https://github.com/halcyon-tech/vscode-db2i"
2626
},
2727
"activationEvents": [
28-
"onStartupFinished"
28+
"onStartupFinished",
29+
"onLanguage:sql"
2930
],
3031
"extensionDependencies": [
3132
"halcyontechltd.code-for-ibmi"

src/language/results/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const getInstance = require(`../../base`);
66
const Configuration = require(`../../configuration`);
77
const html = require(`./html`);
88

9+
function delay(t, v) {
10+
return new Promise(resolve => setTimeout(resolve, t, v));
11+
}
12+
913
class ResultSetPanelProvider {
1014
constructor() {
1115
/** @type {vscode.WebviewView} */
@@ -56,16 +60,25 @@ class ResultSetPanelProvider {
5660
});
5761
}
5862

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+
5972
async focus() {
6073
if (!this._view) {
6174
// Weird one. Kind of a hack. _view.show doesn't work yet because it's not initialized.
6275
// But, we can call a VS Code API to focus on the tab, which then
6376
// 1. calls resolveWebviewView
6477
// 2. sets this._view
6578
await vscode.commands.executeCommand(`vscode-db2i.resultset.focus`);
79+
} else {
80+
this._view.show(true);
6681
}
67-
68-
this._view.show(true);
6982
}
7083

7184
async setLoadingText(content) {
@@ -112,7 +125,9 @@ exports.initialise = (context) => {
112125
let resultSetProvider = new ResultSetPanelProvider();
113126

114127
context.subscriptions.push(
115-
vscode.window.registerWebviewViewProvider(`vscode-db2i.resultset`, resultSetProvider),
128+
vscode.window.registerWebviewViewProvider(`vscode-db2i.resultset`, resultSetProvider, {
129+
webviewOptions: {retainContextWhenHidden: true},
130+
}),
116131

117132
vscode.commands.registerCommand(`vscode-db2i.runEditorStatement`,
118133
/**
@@ -129,6 +144,8 @@ exports.initialise = (context) => {
129144
const editor = vscode.window.activeTextEditor;
130145

131146
if (optionsIsValid || (editor && editor.document.languageId === `sql`)) {
147+
await resultSetProvider.ensureActivation();
148+
132149
/** @type {StatementInfo} */
133150
const statement = (optionsIsValid ? options : this.parseStatement(editor));
134151

0 commit comments

Comments
 (0)