UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

110 lines 4.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GIssueMarker = void 0; exports.getOrCreateGIssueMarker = getOrCreateGIssueMarker; exports.getGIssueMarker = getGIssueMarker; exports.createGIssue = createGIssue; exports.getSeverity = getSeverity; /******************************************************************************** * Copyright (c) 2019-2024 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"); class GIssueMarker extends sprotty_1.SIssueMarkerImpl { constructor() { super(); this.issues = []; this.type = 'marker'; this.features = new Set(sprotty_1.GDecoration.DEFAULT_FEATURES); } computeProjectionCssClasses() { const severityCss = getSeverity(this); this.projectionCssClasses = ['sprotty-issue', 'sprotty-' + severityCss]; } } exports.GIssueMarker = GIssueMarker; /** * Retrieves the `GIssueMarker` contained by the provided model element as * direct child or a newly instantiated `GIssueMarker` if no child * `GIssueMarker` exists. * @param modelElement for which the `GIssueMarker` should be retrieved or created. * @returns the child `GIssueMarker` or a new `GIssueMarker` if no such child exists. */ function getOrCreateGIssueMarker(modelElement) { let issueMarker; issueMarker = getGIssueMarker(modelElement); if (issueMarker === undefined) { issueMarker = new GIssueMarker(); if ((0, sprotty_1.isBoundsAware)(modelElement)) { issueMarker.projectedBounds = modelElement.parentToLocal(modelElement.bounds); } modelElement.add(issueMarker); } return issueMarker; } /** * Retrieves the `GIssueMarker` contained by the provided model element as * direct child or `undefined` if such an `GIssueMarker` does not exist. * @param modelElement for which the `GIssueMarker` should be retrieved. * @returns the child `GIssueMarker` or `undefined` if no such child exists. */ function getGIssueMarker(modelElement) { let issueMarker; for (const child of modelElement.children) { if (child instanceof GIssueMarker) { issueMarker = child; } } return issueMarker; } /** * Creates an `GIssue` with `severity` and `message` set according to * the `kind` and `description` of the provided `Marker`. * @param marker `Marker` for that an `GIssue` should be created. * @returns the created `GIssue`. */ function createGIssue(marker, parent) { const issue = { message: marker.description, severity: 'info' }; switch (marker.kind) { case sprotty_1.MarkerKind.ERROR: { issue.severity = 'error'; break; } case sprotty_1.MarkerKind.INFO: { issue.severity = 'info'; break; } case sprotty_1.MarkerKind.WARNING: { issue.severity = 'warning'; break; } } return issue; } function getSeverity(marker) { let currentSeverity = 'info'; for (const severity of marker.issues.map(s => s.severity)) { if (severity === 'error') { return severity; } if (severity === 'warning' && currentSeverity === 'info') { currentSeverity = severity; } } return currentSeverity; } //# sourceMappingURL=issue-marker.js.map