UNPKG

@abaplint/core

Version:
132 lines 4.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Symbols = void 0; /* eslint-disable max-len */ const LServer = require("vscode-languageserver-types"); const _identifier_1 = require("../abap/4_file_information/_identifier"); const _lsp_utils_1 = require("./_lsp_utils"); const statements_1 = require("../abap/2_statements/statements"); const Statements = require("../abap/2_statements/statements"); const Expressions = require("../abap/2_statements/expressions"); class Symbols { constructor(reg) { this.reg = reg; } find(uri) { const file = _lsp_utils_1.LSPUtils.getABAPFile(this.reg, uri); if (file === undefined) { return []; } const ret = []; ret.push(...this.outputClasses(file)); ret.push(...this.outputForms(file)); ret.push(...this.outputModules(file)); return ret; } selectionRange(identifier) { const pos = identifier.getStart(); const str = identifier.getName(); return LServer.Range.create(pos.getRow() - 1, pos.getCol() - 1, pos.getRow() - 1, pos.getCol() - 1 + str.length); } range(identifer) { const start = identifer.getStart(); const end = identifer.getEnd(); return LServer.Range.create(start.getRow() - 1, start.getCol() - 1, end.getRow() - 1, end.getCol() - 1); } newSymbolRanged(identifier, kind, children, range) { const symbol = { name: identifier.getName(), kind: kind, range: range, selectionRange: this.selectionRange(identifier), children, }; return symbol; } newSymbol(identifier, kind, children) { const symbol = { name: identifier.getName(), kind: kind, range: this.range(identifier), selectionRange: this.selectionRange(identifier), children, }; return symbol; } outputForms(file) { const ret = []; for (const form of file.getInfo().listFormDefinitions()) { const symbol = this.newSymbol(form.identifier, LServer.SymbolKind.Function, []); ret.push(symbol); } return ret; } outputModules(file) { var _a; const ret = []; for (const statement of file.getStatements()) { if (statement.get() instanceof Statements.Module) { const nameToken = (_a = statement.findFirstExpression(Expressions.FormName)) === null || _a === void 0 ? void 0 : _a.getFirstToken(); if (nameToken === undefined) { continue; } const identifier = new _identifier_1.Identifier(nameToken, file.getFilename()); const symbol = this.newSymbol(identifier, LServer.SymbolKind.Module, []); ret.push(symbol); } } return ret; } outputClasses(file) { const ret = []; for (const cla of file.getInfo().listClassDefinitions()) { const children = []; children.push(...this.outputClassAttributes(cla.attributes)); const symbol = this.newSymbol(cla.identifier, LServer.SymbolKind.Class, children); ret.push(symbol); } for (const cla of file.getInfo().listClassImplementations()) { const children = []; children.push(...this.outputMethodImplementations(cla.methods, file)); const symbol = this.newSymbol(cla.identifier, LServer.SymbolKind.Class, children); ret.push(symbol); } return ret; } outputMethodImplementations(methods, file) { const ret = []; for (const method of methods) { const start = method.getStart(); let end = undefined; for (const s of file.getStatements()) { if (s.getFirstToken().getStart().isBefore(start)) { continue; } if (s.get() instanceof statements_1.EndMethod) { end = s.getLastToken().getEnd(); break; } } if (end === undefined) { continue; } const range = LServer.Range.create(start.getRow() - 1, start.getCol() - 1, end.getRow() - 1, end.getCol() - 1); const symbol = this.newSymbolRanged(method, LServer.SymbolKind.Method, [], range); ret.push(symbol); } return ret; } outputClassAttributes(attr) { if (attr === undefined) { return []; } const ret = []; for (const id of attr) { ret.push(this.newSymbol(id.identifier, LServer.SymbolKind.Property, [])); } // todo, also add constants return ret; } } exports.Symbols = Symbols; //# sourceMappingURL=symbols.js.map