UNPKG

sprotty-vscode

Version:

Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)

68 lines 3.11 kB
"use strict"; /******************************************************************************** * Copyright (c) 2022 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.LspWebviewPanelManager = void 0; const webview_panel_manager_1 = require("../webview-panel-manager"); const lsp_utils_1 = require("./lsp-utils"); const lsp_webview_endpoint_1 = require("./lsp-webview-endpoint"); const protocol_1 = require("./protocol"); /** * A webview panel manager to be connected with a language server to provide diagram contents. */ class LspWebviewPanelManager extends webview_panel_manager_1.WebviewPanelManager { constructor(options) { super(options); options.languageClient.onNotification(protocol_1.acceptMessageType, message => this.acceptFromLanguageServer(message)); options.languageClient.onNotification(protocol_1.openInTextEditorMessageType, message => (0, lsp_utils_1.openInTextEditor)(message)); } get languageClient() { return this.options.languageClient; } createEndpoint(identifier) { var _a, _b; const webviewContainer = this.createWebview(identifier); const participant = this.messenger.registerWebviewPanel(webviewContainer); const endpoint = new lsp_webview_endpoint_1.LspWebviewEndpoint({ languageClient: this.languageClient, webviewContainer, messenger: this.messenger, messageParticipant: participant, identifier }); (_b = (_a = this.options).configureEndpoint) === null || _b === void 0 ? void 0 : _b.call(_a, endpoint); return endpoint; } didCloseWebview(endpoint) { var _a; super.didCloseWebview(endpoint); try { this.languageClient.sendNotification(protocol_1.didCloseMessageType, (_a = endpoint.diagramIdentifier) === null || _a === void 0 ? void 0 : _a.clientId); } catch (err) { // Ignore the error and proceed } } acceptFromLanguageServer(message) { for (const endpoint of this.endpoints) { if (endpoint.diagramIdentifier && endpoint.diagramIdentifier.clientId === message.clientId) { endpoint.sendAction(message); } } } } exports.LspWebviewPanelManager = LspWebviewPanelManager; //# sourceMappingURL=lsp-webview-panel-manager.js.map