UNPKG

@eclipse-glsp/theia-integration

Version:

Glue code to integrate GLSP clients into Eclipse Theia

108 lines 5.31 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectionWithRange = exports.SelectionWithElementIds = exports.OptionsWithSelection = exports.TheiaOpenerOptionsNavigationService = void 0; /******************************************************************************** * Copyright (c) 2020-2023 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 lib_1 = require("@eclipse-glsp/client/lib"); const inversify_1 = require("@theia/core/shared/inversify"); const browser_1 = require("@theia/editor/lib/browser"); /** * Service for translating `OpenerOptions` into a `NavigateToTargetAction`. * * This service is typically used to determine requested selections from Theia * opener options on open or reveal of a diagram widget. Diagram widgets can * then dispatch the determined diagram navigation actions once the widget is * initialized. * * This service will forward the `selection` property of the `OpenerOptions` * in the form of arguments in the issued `NavigateToTargetAction` as follows: * *(a)* the property `elementIds: string[]` as element ids * *(b)* `start` with `line: number` and `character: number` * *(c)* any simple-typed properties that are direct properties of `selection` * * (bound in Theia main DI container) */ let TheiaOpenerOptionsNavigationService = class TheiaOpenerOptionsNavigationService { determineNavigations(uri, options) { if (OptionsWithSelection.is(options)) { const selection = options.selection; const navigationTarget = { uri }; Object.keys(selection).forEach(key => { const value = selection[key]; if (typeof value !== 'object') { lib_1.NavigationTarget.addArgument(navigationTarget, key, value); } }); if (SelectionWithElementIds.is(selection)) { lib_1.NavigationTarget.setElementIds(navigationTarget, ...selection.elementIds); } if (browser_1.Range.is(selection)) { lib_1.NavigationTarget.setTextPosition(navigationTarget, { line: selection.start.line, character: selection.start.character }); } return [lib_1.NavigateToTargetAction.create(navigationTarget)]; } return []; } }; exports.TheiaOpenerOptionsNavigationService = TheiaOpenerOptionsNavigationService; exports.TheiaOpenerOptionsNavigationService = TheiaOpenerOptionsNavigationService = __decorate([ (0, inversify_1.injectable)() ], TheiaOpenerOptionsNavigationService); var OptionsWithSelection; (function (OptionsWithSelection) { function is(options) { return options !== undefined && 'selection' in options; } OptionsWithSelection.is = is; function elementId(options) { if (!OptionsWithSelection.is(options)) { return undefined; } if (!SelectionWithElementIds.is(options.selection)) { return undefined; } return options.selection.elementIds; } OptionsWithSelection.elementId = elementId; })(OptionsWithSelection || (exports.OptionsWithSelection = OptionsWithSelection = {})); var SelectionWithElementIds; (function (SelectionWithElementIds) { function is(selection) { return selection !== undefined && 'elementIds' in selection; } SelectionWithElementIds.is = is; function createRange(elementIds) { return { elementIds, start: { line: -1, character: -1 }, end: { line: -1, character: -1 } }; } SelectionWithElementIds.createRange = createRange; })(SelectionWithElementIds || (exports.SelectionWithElementIds = SelectionWithElementIds = {})); var SelectionWithRange; (function (SelectionWithRange) { function is(selection) { return browser_1.Range.is(selection); } SelectionWithRange.is = is; })(SelectionWithRange || (exports.SelectionWithRange = SelectionWithRange = {})); //# sourceMappingURL=theia-opener-options-navigation-service.js.map