UNPKG

@eclipse-glsp/theia-integration

Version:

Glue code to integrate GLSP clients into Eclipse Theia

148 lines 6.28 kB
"use strict"; 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); }; var TheiaGLSPMessageService_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.TheiaGLSPMessageService = void 0; /******************************************************************************** * Copyright (c) 2023-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 client_1 = require("@eclipse-glsp/client"); const core_1 = require("@theia/core"); const browser_1 = require("@theia/core/lib/browser"); const inversify_1 = require("@theia/core/shared/inversify"); let TheiaGLSPMessageService = TheiaGLSPMessageService_1 = class TheiaGLSPMessageService { constructor() { this.progressReporters = new Map(); } dispose() { this.progressReporters.forEach(progress => progress.cancel()); this.progressReporters.clear(); } handle(action) { if (client_1.MessageAction.is(action)) { return this.message(action); } if (client_1.StartProgressAction.is(action)) { return this.startProgress(action); } if (client_1.UpdateProgressAction.is(action)) { return this.updateProgress(action); } if (client_1.EndProgressAction.is(action)) { return this.endProgress(action); } } message(action) { var _a; if (!this.shouldShowMessage(action)) { return; } const method = this.toMessageServiceMethod(action.severity); const text = action.message; const details = (_a = action.details) !== null && _a !== void 0 ? _a : ''; const actions = details ? [TheiaGLSPMessageService_1.SHOW_DETAILS_LABEL] : []; this.messageService[method](text, undefined, ...actions).then(result => { if (result === TheiaGLSPMessageService_1.SHOW_DETAILS_LABEL) { this.showDetailsDialog(text, details); } }); } toMessageServiceMethod(severity) { switch (severity) { case 'ERROR': return 'error'; case 'WARNING': return 'warn'; case 'INFO': return 'info'; } return 'log'; } shouldShowMessage(action) { return action.severity !== 'NONE'; } showDetailsDialog(title, msg) { const wrappedMsg = wrapMessage(msg); return new browser_1.ConfirmDialog({ title, msg: wrappedMsg }).open(); } startProgress(action) { const { progressId, title, message, percentage } = action; const newPercentage = (percentage !== null && percentage !== void 0 ? percentage : -1) >= 0 ? percentage : undefined; this.messageService .showProgress({ text: title }) // .then(progress => { this.progressReporters.set(progressId, progress); progress.report({ message, work: newPercentage ? { done: newPercentage, total: 100 } : undefined }); }); } progressReporterId(widgetId, progressId) { return `${widgetId}_${progressId}`; } updateProgress(action) { const { progressId, message, percentage } = action; const newPercentage = (percentage !== null && percentage !== void 0 ? percentage : -1) >= 0 ? percentage : undefined; const progress = this.progressReporters.get(progressId); if (!progress) { return; } progress.report({ message, work: newPercentage ? { done: newPercentage, total: 100 } : undefined }); } endProgress(action) { const { progressId } = action; const progress = this.progressReporters.get(progressId); if (!progress) { return; } this.progressReporters.delete(progressId); progress.cancel(); } }; exports.TheiaGLSPMessageService = TheiaGLSPMessageService; TheiaGLSPMessageService.SHOW_DETAILS_LABEL = 'Show details'; __decorate([ (0, inversify_1.inject)(core_1.MessageService), __metadata("design:type", core_1.MessageService) ], TheiaGLSPMessageService.prototype, "messageService", void 0); __decorate([ (0, inversify_1.preDestroy)(), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], TheiaGLSPMessageService.prototype, "dispose", null); exports.TheiaGLSPMessageService = TheiaGLSPMessageService = TheiaGLSPMessageService_1 = __decorate([ (0, inversify_1.injectable)() ], TheiaGLSPMessageService); /** * Wraps the given message in a pre-formatted, * scrollable div. * @param msg */ function wrapMessage(msg) { const scrollDiv = document.createElement('div'); scrollDiv.className = 'scroll-div'; const pre = document.createElement('pre'); pre.textContent = msg; scrollDiv.appendChild(pre); return scrollDiv; } //# sourceMappingURL=theia-glsp-message-service.js.map