UNPKG

perlnavigator-server

Version:

Perl language server

82 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildNav = void 0; const types_1 = require("./types"); const vscode_uri_1 = require("vscode-uri"); function buildNav(stdout, filePath, fileuri) { stdout = stdout.replaceAll("\r", ""); // Windows let perlDoc = { elems: new Map(), canonicalElems: new Map(), autoloads: new Map(), imported: new Map(), parents: new Map(), uri: fileuri, }; stdout.split("\n").forEach((perl_elem) => { parseElem(perl_elem, perlDoc); }); return perlDoc; } exports.buildNav = buildNav; function parseElem(perlTag, perlDoc) { var items = perlTag.split("\t"); if (items.length != 7) { return; } if (!items[0] || items[0] == "_") return; // Need a look-up key const name = items[0]; const type = items[1] || ""; const typeDetail = items[2] || ""; const file = items[3] || ""; const pack = items[4] || ""; const lines = items[5].split(";"); const startLine = lines[0] ? +lines[0] : 0; const endLine = lines[1] ? +lines[1] : startLine; const value = items[6] || ""; if (type == types_1.TagKind.UseStatement) { // Explictly loaded module. Helpful for focusing autocomplete results perlDoc.imported.set(name, startLine); // if(/\bDBI$/.exec(name)) perlDoc.imported.set(name + "::db", true); // TODO: Build mapping of common constructors to types return; // Don't store it as an element } if (type == types_1.TagKind.Canonical2) { perlDoc.parents.set(name, typeDetail); return; // Don't store it as an element } // Add anyway const newElem = { name: name, type: type, typeDetail: typeDetail, uri: vscode_uri_1.default.file(file).toString(), package: pack, line: startLine, lineEnd: endLine, value: value, source: types_1.ElemSource.symbolTable, }; // Move fancy object types into the typeDetail field???? if (type.length > 1) { // We overwrite, so the last typed element is the canonical one. No reason for this. perlDoc.canonicalElems.set(name, newElem); } if (type == types_1.PerlSymbolKind.Canonical) { // This object is only intended as the canonicalLookup, not for anything else. // This doesn't do anything until fancy object types are moved into the typeDetail field return; } if (type == types_1.PerlSymbolKind.AutoLoadVar) { perlDoc.autoloads.set(name, newElem); return; // Don't store it as an element } addVal(perlDoc.elems, name, newElem); return; } function addVal(map, key, value) { let array = map.get(key) || []; array.push(value); map.set(key, array); } //# sourceMappingURL=parseTags.js.map