theia-sprotty
Version:
Glue code for sprotty diagrams in a Theia IDE
93 lines • 4.53 kB
JavaScript
;
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License") you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
var browser_1 = require("@theia/languages/lib/browser");
var uri_1 = require("@theia/core/lib/common/uri");
var acceptMessageType = new browser_1.NotificationType('diagram/accept');
var didCloseMessageType = new browser_1.NotificationType('diagram/didClose');
var openInTextEditorMessageType = new browser_1.NotificationType('diagram/openInTextEditor');
/**
* Connects sprotty DiagramServers to a Theia LanguageClientContribution.
*
* Used to tunnel sprotty actions to and from the sprotty server through
* the LSP.
*
* Instances bridge the gap between the sprotty DI containers (one per
* diagram) and a specific language client from the Theia DI container
* (one per application).
*/
var TheiaSprottyConnector = /** @class */ (function () {
function TheiaSprottyConnector(languageClientContribution, fileSaver, editorManager, diagramWidgetRegistry, workspace, quickPickService) {
var _this = this;
this.languageClientContribution = languageClientContribution;
this.fileSaver = fileSaver;
this.editorManager = editorManager;
this.diagramWidgetRegistry = diagramWidgetRegistry;
this.workspace = workspace;
this.quickPickService = quickPickService;
this.servers = [];
this.languageClientContribution.languageClient.then(function (lc) {
lc.onNotification(acceptMessageType, _this.receivedThroughLsp.bind(_this));
lc.onNotification(openInTextEditorMessageType, _this.openInTextEditor.bind(_this));
}).catch(function (err) { return console.error(err); });
}
TheiaSprottyConnector.prototype.connect = function (diagramServer) {
this.servers.push(diagramServer);
diagramServer.connect(this);
};
TheiaSprottyConnector.prototype.disconnect = function (diagramServer) {
var index = this.servers.indexOf(diagramServer);
if (index >= 0)
this.servers.splice(index, 0);
diagramServer.disconnect();
this.languageClientContribution.languageClient.then(function (lc) { return lc.sendNotification(didCloseMessageType, diagramServer.clientId); });
};
TheiaSprottyConnector.prototype.save = function (uri, action) {
this.fileSaver.save(uri, action);
};
TheiaSprottyConnector.prototype.openInTextEditor = function (message) {
var uri = new uri_1.default(message.location.uri);
if (!message.forceOpen) {
this.editorManager.all.forEach(function (editorWidget) {
var currentTextEditor = editorWidget.editor;
if (editorWidget.isVisible && uri.toString(true) === currentTextEditor.uri.toString(true)) {
currentTextEditor.cursor = message.location.range.start;
currentTextEditor.revealRange(message.location.range);
currentTextEditor.selection = message.location.range;
}
});
}
else {
this.editorManager.open(uri).then(function (editorWidget) {
var editor = editorWidget.editor;
editor.cursor = message.location.range.start;
editor.revealRange(message.location.range);
editor.selection = message.location.range;
});
}
};
TheiaSprottyConnector.prototype.showStatus = function (widgetId, status) {
var widget = this.diagramWidgetRegistry.getWidgetById(widgetId);
if (widget)
widget.setStatus(status);
};
TheiaSprottyConnector.prototype.sendThroughLsp = function (message) {
this.languageClientContribution.languageClient.then(function (lc) { return lc.sendNotification(acceptMessageType, message); });
};
TheiaSprottyConnector.prototype.getLanguageClient = function () {
return this.languageClientContribution.languageClient;
};
TheiaSprottyConnector.prototype.receivedThroughLsp = function (message) {
this.servers.forEach(function (element) {
element.messageReceived(message);
});
};
return TheiaSprottyConnector;
}());
exports.TheiaSprottyConnector = TheiaSprottyConnector;
//# sourceMappingURL=theia-sprotty-connector.js.map