UNPKG

@abaplint/core

Version:
67 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Implementation = void 0; const _abap_object_1 = require("../objects/_abap_object"); const _lsp_utils_1 = require("./_lsp_utils"); const _lookup_1 = require("./_lookup"); const types_1 = require("../abap/types"); const syntax_1 = require("../abap/5_syntax/syntax"); const _reference_1 = require("../abap/5_syntax/_reference"); // note: finding implementations might be slow, ie finding method implementations currently searches the full registry // go to implementation class Implementation { constructor(reg) { this.reg = reg; } find(textDocument, position) { const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, textDocument.uri); if (file === undefined) { return []; } const obj = this.reg.getObject(file.getObjectType(), file.getObjectName()); if (!(obj instanceof _abap_object_1.ABAPObject)) { return []; } const found = _lsp_utils_1.LSPUtils.findCursor(this.reg, { textDocument, position }); if (found === undefined) { return []; } const lookup = _lookup_1.LSPLookup.lookup(found, this.reg, obj); if (lookup === null || lookup === void 0 ? void 0 : lookup.implementation) { return [lookup === null || lookup === void 0 ? void 0 : lookup.implementation]; } if ((lookup === null || lookup === void 0 ? void 0 : lookup.definitionId) instanceof types_1.MethodDefinition) { return this.findMethodImplementations(lookup.definitionId); } return []; } findMethodImplementations(def) { const ret = []; // note that this searches _everything_ for (const obj of this.reg.getObjects()) { if (this.reg.isDependency(obj) || !(obj instanceof _abap_object_1.ABAPObject)) { continue; } const found = this.searchReferences(new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop(), def); ret.push(...found); } return ret; } searchReferences(scope, id) { const ret = []; for (const r of scope.getData().references) { if (r.referenceType === _reference_1.ReferenceType.MethodImplementationReference && r.resolved && r.resolved.getFilename() === id.getFilename() && r.resolved.getStart().equals(id.getStart())) { ret.push(_lsp_utils_1.LSPUtils.identiferToLocation(r.position)); } } for (const c of scope.getChildren()) { ret.push(...this.searchReferences(c, id)); } return ret; } } exports.Implementation = Implementation; //# sourceMappingURL=implementation.js.map