UNPKG

@autobe/agent

Version:

AI backend server code generator

48 lines 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.printErrorHints = printErrorHints; const utils_1 = require("@autobe/utils"); /** * Prints error hints for a given code and its diagnostics. * * @param code The code to analyze. * @param diagnostics The diagnostics to use for error hinting. */ function printErrorHints(code, diagnostics) { const lines = code.split("\n"); let cursor = 0; const hints = []; lines.forEach((line, index, arr) => { const lineStart = cursor; cursor += line.length + 1; // +1 for the newline character diagnostics.forEach((diag) => { if (diag.start === null || diag.start === undefined) { return; } // Check if the diagnostic start position falls within the current line if (diag.start >= lineStart && diag.start < cursor) { // Handle multi-line error messages by escaping newlines const errorMessage = String(diag.messageText).replace(/\n/g, "\\n"); const targetLine = line + " // error: " + errorMessage; // targetLine만 덮어써서 새로운 배열을 만들어야 한다. const hint = arr .slice(0, index) .concat(targetLine) .concat(arr.slice(index + 1)) .join("\n"); hints.push(hint); } }); }); return hints .map((h, i) => { return utils_1.StringUtil.trim ` hint #${i + 1}: \`\`\`typescript ${h} \`\`\` `; }) .join("\n\n"); } //# sourceMappingURL=printErrorHints.js.map