@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
116 lines • 5.22 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GLSPCommandStack = void 0;
/********************************************************************************
* Copyright (c) 2019-2025 EclipseSource 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
********************************************************************************/
const sprotty_1 = require("@eclipse-glsp/sprotty");
const inversify_1 = require("inversify");
const editor_context_service_1 = require("./editor-context-service");
let GLSPCommandStack = class GLSPCommandStack extends sprotty_1.CommandStack {
constructor() {
super(...arguments);
this.toDispose = new sprotty_1.DisposableCollection();
this.onCommandExecutedEmitter = new sprotty_1.Emitter();
}
get onCommandExecuted() {
return this.onCommandExecutedEmitter.event;
}
initialize() {
super.initialize();
this.toDispose.push(this.onCommandExecutedEmitter);
}
dispose() {
this.toDispose.dispose();
}
// Use lazyInjector to resolve circular dependency
// GLSPActionDispatcher --> GLSPCommandStack --> EditorContextService --> GLSPActionDispatcher
get editorContext() {
return this.lazyInjector.get(editor_context_service_1.EditorContextService);
}
/**
* @deprecated Use the `EditorContext.onModelRootChanged` event instead
*/
get onModelRootChanged() {
return this.editorContext.onModelRootChanged;
}
/**
* Client-side undo/redo is not supported in GLSP. The server is responsible for handling undo/redo requests.
* If this method get called it's probably a mistake and a warning is logged
*/
undo() {
this.logger.warn(this, 'GLSPCommandStack.undo() was called. This should never happen as the GLSP server is responsible for handling undo requests');
return this.currentModel;
}
/**
* Client-side undo/redo is not supported in GLSP. The server is responsible for handling undo/redo requests.
* If this method get called it's probably a mistake and a warning is logged
*/
redo() {
this.logger.warn(this, 'GLSPCommandStack.redo() was called. This should never happen as the GLSP server is responsible for handling redo requests');
return this.currentModel;
}
/**
* Client-side undo/redo is not supported in GLSP.
* To avoid unnecessary infraction with the command stack (pushing/merging/popping commands)
* related methods are overridden to no-ops.
*/
pushToUndoStack(command) {
// no-op
}
/**
* Client-side undo/redo is not supported in GLSP.
* To avoid unnecessary infraction with the command stack (pushing/merging/popping commands)
* related methods are overridden to no-ops.
*/
mergeOrPush(command, context) {
// no-op
}
async execute(command) {
const result = await super.execute(command);
this.onCommandExecutedEmitter.fire({ command, newRoot: result });
return result;
}
};
exports.GLSPCommandStack = GLSPCommandStack;
__decorate([
(0, inversify_1.inject)(sprotty_1.LazyInjector),
__metadata("design:type", Object)
], GLSPCommandStack.prototype, "lazyInjector", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], GLSPCommandStack.prototype, "initialize", null);
__decorate([
(0, inversify_1.preDestroy)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], GLSPCommandStack.prototype, "dispose", null);
exports.GLSPCommandStack = GLSPCommandStack = __decorate([
(0, inversify_1.injectable)()
], GLSPCommandStack);
//# sourceMappingURL=command-stack.js.map