UNPKG

codn_ts

Version:

智能代码分析工具 - 支持语义搜索、调用链分析和代码结构可视化,对大模型/AI agent 友好

40 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkRealFuncChar = checkRealFuncChar; /** * 查找符号名称在声明中的精确字符位置 * @param rawLine 包含符号声明的原始行文本 * @param line 符号的起始行号(0-based) * @param funcChar 符号的起始字符位置(0-based) * @param fullName 符号的完整名称 * @param kind 符号类型(LSP SymbolKind 数字) * @param uri 文档URI * @param funcLine 符号的起始行号(1-based,用于日志) * @returns 修正后的行号和字符位置 */ function checkRealFuncChar(rawLine, line, funcChar, fullName, kind, uri) { // 创建带单词边界的正则表达式 const pattern = new RegExp(`\\b${escapeRegExp(fullName)}\\b`); const match = pattern.exec(rawLine); // 处理多行声明(如JSDoc注释后的函数) const lines = rawLine.split("\n"); let currentPos = 0; let foundLine = line; let foundChar = funcChar; for (let i = 0; i < lines.length; i++) { const lineText = lines[i]; const lineMatch = pattern.exec(lineText); if (lineMatch) { foundLine = line + i; foundChar = lineMatch.index; break; } currentPos += lineText.length + 1; // +1 for newline } return { line: foundLine, character: foundChar }; } // 辅助函数:转义正则表达式特殊字符 function escapeRegExp(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } //# sourceMappingURL=symbol_utils.js.map