UNPKG

@abaplint/core

Version:
98 lines 3.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CodeLens = void 0; const LServer = require("vscode-languageserver-types"); const _lsp_utils_1 = require("./_lsp_utils"); const syntax_1 = require("../abap/5_syntax/syntax"); const _abap_object_1 = require("../objects/_abap_object"); const _reference_1 = require("../abap/5_syntax/_reference"); const types_1 = require("../abap/types"); class CodeLens { constructor(reg) { this.reg = reg; } list(textDocument, settings = { messageText: true, dynamicExceptions: true }) { var _a; const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, textDocument.uri); if (file === undefined) { return []; } const obj = this.reg.findObjectForFile(file); if (obj === undefined || !(obj instanceof _abap_object_1.ABAPObject)) { return []; } const top = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop(); const ret = []; if (settings.messageText === true) { const list = this.reg.getMSAGReferences().listByFilename(file.getFilename()); for (const l of list) { const msag = this.reg.getObject("MSAG", l.messageClass); if (msag === undefined) { continue; } const text = (_a = msag.getByNumber(l.number)) === null || _a === void 0 ? void 0 : _a.getMessage(); if (text === undefined) { continue; } ret.push({ range: _lsp_utils_1.LSPUtils.tokenToRange(l.token), command: LServer.Command.create(text, "") }); } } if (settings.dynamicExceptions === true) { for (const ref of this.findMethodReferences(top, file)) { if (!(ref.resolved instanceof types_1.MethodDefinition)) { continue; } let text = ""; for (const e of ref.resolved.getRaising()) { if (this.isDynamicException(e, top)) { if (text === "") { text = "Dynamic Exceptions: "; } else { text += " & "; } text += e.toUpperCase(); } } if (text !== "") { ret.push({ range: _lsp_utils_1.LSPUtils.tokenToRange(ref.position.getToken()), command: LServer.Command.create(text, "") }); } } } return ret; } isDynamicException(name, top) { var _a; // todo: this method only works with global exceptions? let current = name; while (current !== undefined) { if (current.toUpperCase() === "CX_DYNAMIC_CHECK") { return true; } current = (_a = top.findClassDefinition(current)) === null || _a === void 0 ? void 0 : _a.getSuperClass(); } return false; } findMethodReferences(node, file) { const ret = []; if (node.getIdentifier().filename === file.getFilename()) { for (const r of node.getData().references) { if (r.referenceType === _reference_1.ReferenceType.MethodReference) { ret.push(r); } } } for (const c of node.getChildren()) { ret.push(...this.findMethodReferences(c, file)); } return ret; } } exports.CodeLens = CodeLens; //# sourceMappingURL=code_lens.js.map