Working live beans multiple webviews

This commit is contained in:
BoykoAlex
2019-08-23 18:53:48 -04:00
parent 276fb164a3
commit 7dfb35b335
2 changed files with 34 additions and 10 deletions

View File

@@ -38,11 +38,15 @@ export class VSCodeWebViewDiagramServer extends DiagramServer {
protected vscode: any;
listen(vscode: any): void {
console.log('Adding listener!');
window.addEventListener('message', (event: any) => {
const message = event.data; // The json data that the extension sent
console.log('Message Received');
this.messageReceived(message);
if (event.data == 'test') {
console.log('Received TEST message!');
} else {
console.log('Message Received');
this.messageReceived(message);
}
});
this.vscode = vscode;

View File

@@ -54,7 +54,7 @@ class LiveBeansView {
// Otherwise, create a new panel.
const panel = vscode.window.createWebviewPanel(
LiveBeansView.viewType,
'Live Beans',
clientId,
column || vscode.ViewColumn.One,
{
// Enable javascript in the webview
@@ -243,20 +243,40 @@ class LSWebViewToWebsocketBridge implements LSWebViewBridge {
const SPROTTY_LSP_NOTIFICATION = new NotificationType<any, void>("sts/sprotty");
class LSWebViewToLSPBridge implements LSWebViewBridge {
static bridges: LSWebViewToLSPBridge[] = [];
static initialized = false;
private client: LanguageClient;
private panel: vscode.WebviewPanel;
constructor(panel: vscode.WebviewPanel, client: LanguageClient) {
client.onReady().then(() => {
client.onNotification(SPROTTY_LSP_NOTIFICATION, async (params: any) => {
panel.webview.postMessage(params)
});
});
this.client = client;
this.panel = panel;
if (!LSWebViewToLSPBridge.initialized) {
LSWebViewToLSPBridge.initialized = true;
client.onReady().then(() => {
client.onNotification(SPROTTY_LSP_NOTIFICATION, async (params: any) => {
LSWebViewToLSPBridge.bridges.forEach(bridge => {
bridge.panel.webview.postMessage(params)
});
});
});
}
}
LSWebViewToLSPBridge.bridges.push(this);
panel.onDidDispose(() => {
const index = LSWebViewToLSPBridge.bridges.indexOf(this);
if (index >= 0) {
LSWebViewToLSPBridge.bridges.splice(index, 1);
}
});
}
sendToLs(message: any) {
this.client.onReady().then(() => {
this.client.sendNotification(SPROTTY_LSP_NOTIFICATION, message);