sprotty-vscode-webview
Version:
Integration of Sprotty in a VS Code extensions (WebView part)
55 lines • 2.67 kB
JavaScript
;
/********************************************************************************
* Copyright (c) 2018 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.VscodeLspEditDiagramServer = void 0;
const sprotty_1 = require("sprotty");
const sprotty_protocol_1 = require("sprotty-protocol");
const editing_1 = require("sprotty-vscode-protocol/lib/lsp/editing");
const vscode_diagram_server_1 = require("../../vscode-diagram-server");
const traceable_1 = require("./traceable");
class VscodeLspEditDiagramServer extends vscode_diagram_server_1.VscodeDiagramServer {
initialize(registry) {
super.initialize(registry);
registry.register(sprotty_1.EditLabelAction.KIND, this);
registry.register(editing_1.WorkspaceEditAction.KIND, this);
registry.register("reconnect", this);
}
handleLocally(action) {
if (action.kind === sprotty_1.EditLabelAction.KIND) {
const label = this.getElement(action.labelId);
if (label && (0, sprotty_protocol_1.getBasicType)(label) === 'label' && (0, traceable_1.isTraceable)(label)) {
const editKind = ((0, sprotty_protocol_1.getSubType)(label) === 'xref') ? 'xref' : 'name';
this.forwardToServer({
kind: editing_1.LspLabelEditAction.KIND,
initialText: label.text,
location: {
uri: (0, traceable_1.getURI)(label).toString(),
range: (0, traceable_1.getRange)(label)
},
editKind
});
return false;
}
}
return super.handleLocally(action);
}
getElement(elementId) {
return (0, sprotty_protocol_1.findElement)(this.currentRoot, elementId);
}
}
exports.VscodeLspEditDiagramServer = VscodeLspEditDiagramServer;
//# sourceMappingURL=vscode-lsp-edit-diagram-server.js.map