import { findCalleeNames, findCallerNames } from '../../../db/index.js';
import { extractLeadingComment, splitIdentifier } from './text-utils.js';
/**
 * Build graph-enriched text for a symbol using dependency context.
 */
export function buildStructuredText(node, file, lines, db) {
    const readable = splitIdentifier(node.name);
    const parts = [`${node.kind} ${node.name} (${readable}) in ${file}`];
    const startLine = Math.max(0, node.line - 1);
    const sigLine = lines[startLine] || '';
    const paramMatch = sigLine.match(/\(([^)]*)\)/);
    if (paramMatch?.[1]?.trim()) {
        parts.push(`Parameters: ${paramMatch[1].trim()}`);
    }
    const callees = findCalleeNames(db, node.id);
    if (callees.length > 0) {
        parts.push(`Calls: ${callees.slice(0, 10).join(', ')}`);
    }
    const callers = findCallerNames(db, node.id);
    if (callers.length > 0) {
        parts.push(`Called by: ${callers.slice(0, 10).join(', ')}`);
    }
    const comment = extractLeadingComment(lines, startLine);
    if (comment) {
        parts.push(comment);
    }
    else {
        const endLine = Math.min(lines.length, startLine + 4);
        const snippet = lines.slice(startLine, endLine).join('\n').trim();
        if (snippet)
            parts.push(snippet);
    }
    return parts.join('\n');
}
//# sourceMappingURL=structured.js.map