@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
78 lines • 4.16 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.NavigationTargetResolver = void 0;
/********************************************************************************
* Copyright (c) 2020-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");
const inversify_1 = require("inversify");
/**
* Resolves `NavigationTargets` to element ids.
*
* If the `NavigationTarget` doesn't have element ids itself, this resolver queries the server via a
* `ResolveNavigationTargetAction` for element ids.
*/
let NavigationTargetResolver = class NavigationTargetResolver {
async resolve(navigationTarget) {
return this.resolveWithSourceUri(this.diagramOptions.sourceUri, navigationTarget);
}
async resolveWithSourceUri(sourceUri, target) {
const targetUri = decodeURIComponent(target.uri);
const normalizedSourceUri = sourceUri === null || sourceUri === void 0 ? void 0 : sourceUri.replace(/^file:\/\//, '');
const normalizedTargetUri = targetUri.replace(/^file:\/\//, '');
if (normalizedSourceUri && normalizedSourceUri !== normalizedTargetUri) {
// different URI, so we can't resolve it locally
this.logger.info("Source and Target URI are different. Can't resolve locally.", normalizedSourceUri, normalizedTargetUri);
return undefined;
}
if (sprotty_1.NavigationTarget.getElementIds(target).length > 0) {
return sprotty_1.SetResolvedNavigationTargetAction.create(sprotty_1.NavigationTarget.getElementIds(target));
}
const response = await this.requestResolution(target);
if (sprotty_1.SetResolvedNavigationTargetAction.is(response)) {
return response;
}
return undefined;
}
requestResolution(target) {
return this.dispatcher.request(sprotty_1.ResolveNavigationTargetAction.create(target));
}
};
exports.NavigationTargetResolver = NavigationTargetResolver;
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher),
__metadata("design:type", Object)
], NavigationTargetResolver.prototype, "dispatcher", void 0);
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.ILogger),
__metadata("design:type", Object)
], NavigationTargetResolver.prototype, "logger", void 0);
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.IDiagramOptions),
__metadata("design:type", Object)
], NavigationTargetResolver.prototype, "diagramOptions", void 0);
exports.NavigationTargetResolver = NavigationTargetResolver = __decorate([
(0, inversify_1.injectable)()
], NavigationTargetResolver);
//# sourceMappingURL=navigation-target-resolver.js.map