UNPKG

sprotty-vscode

Version:

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

68 lines 3.21 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.LspSprottyEditorProvider = void 0; const sprotty_editor_provider_1 = require("../sprotty-editor-provider"); const lsp_utils_1 = require("./lsp-utils"); const lsp_webview_endpoint_1 = require("./lsp-webview-endpoint"); const protocol_1 = require("./protocol"); /** * A custom editor provider to be connected with a language server to provide diagram contents. */ class LspSprottyEditorProvider extends sprotty_editor_provider_1.SprottyEditorProvider { 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, webviewContainer) { var _a, _b; 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; } disposeDocument(document) { var _a, _b; super.disposeDocument(document); try { this.languageClient.sendNotification(protocol_1.didCloseMessageType, (_b = (_a = document.endpoint) === null || _a === void 0 ? void 0 : _a.diagramIdentifier) === null || _b === void 0 ? void 0 : _b.clientId); } catch (err) { // Ignore the error and proceed } } acceptFromLanguageServer(message) { for (const document of this.documents) { const endpoint = document.endpoint; if (endpoint && endpoint.diagramIdentifier && endpoint.diagramIdentifier.clientId === message.clientId) { endpoint.sendAction(message); } } } } exports.LspSprottyEditorProvider = LspSprottyEditorProvider; //# sourceMappingURL=lsp-sprotty-editor-provider.js.map