sprotty-vscode
Version:
Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)
65 lines • 2.92 kB
JavaScript
;
/********************************************************************************
* 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.LspSprottyViewProvider = void 0;
const sprotty_view_provider_1 = require("../sprotty-view-provider");
const lsp_utils_1 = require("./lsp-utils");
const lsp_webview_endpoint_1 = require("./lsp-webview-endpoint");
const protocol_1 = require("./protocol");
/**
* A view provider to be connected with a language server to provide diagram contents.
*/
class LspSprottyViewProvider extends sprotty_view_provider_1.SprottyViewProvider {
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(webviewContainer, identifier) {
var _a, _b;
const participant = this.messenger.registerWebviewView(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) {
if (this.endpoint) {
this.endpoint.sendAction(message);
}
}
}
exports.LspSprottyViewProvider = LspSprottyViewProvider;
//# sourceMappingURL=lsp-sprotty-view-provider.js.map