sprotty-vscode
Version:
Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)
54 lines • 2.5 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.LspWebviewEndpoint = void 0;
const lsp_1 = require("sprotty-vscode-protocol/lib/lsp");
const webview_endpoint_1 = require("../webview-endpoint");
const protocol_1 = require("./protocol");
/**
* A webview endpoint subclass that forwards messages from the webview to a language server
* via the Language Server Protocol.
*/
class LspWebviewEndpoint extends webview_endpoint_1.WebviewEndpoint {
constructor(options) {
super(options);
this.languageClient = options.languageClient;
}
connect() {
super.connect();
this.disposables.push(this.messenger.onRequest(lsp_1.LspRequest, async (request) => {
const result = request.params === undefined
? await this.languageClient.sendRequest(request.method)
: await this.languageClient.sendRequest(request.method, request.params);
const response = {
jsonrpc: '2.0',
id: request.id,
result
};
return response;
}, { sender: this.messageParticipant }));
this.disposables.push(this.messenger.onNotification(lsp_1.LspNotification, notification => {
this.languageClient.sendNotification(notification.method, notification.params);
}, { sender: this.messageParticipant }));
}
async receiveAction(message) {
await super.receiveAction(message);
await this.languageClient.sendNotification(protocol_1.acceptMessageType, message);
}
}
exports.LspWebviewEndpoint = LspWebviewEndpoint;
//# sourceMappingURL=lsp-webview-endpoint.js.map