"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractSymbols = extractSymbols;
const languages_1 = require("../../lib/parsers/languages");
/** Map of common code fence language tags to language names used by the registry. */
const TAG_TO_LANGUAGE = {
    ts: 'typescript',
    typescript: 'typescript',
    tsx: 'tsx',
    js: 'javascript',
    javascript: 'javascript',
    jsx: 'javascript',
};
/**
 * Extract top-level symbol names from a code block using tree-sitter.
 * Returns [] for unsupported languages or on parse failure.
 */
async function extractSymbols(code, language) {
    const lang = TAG_TO_LANGUAGE[language.toLowerCase()];
    if (!lang || !(0, languages_1.isLanguageSupported)(lang))
        return [];
    try {
        const tree = await (0, languages_1.parseSource)(code, lang);
        if (!tree)
            return [];
        try {
            const mapper = (0, languages_1.getMapper)(lang);
            const symbols = mapper.extractSymbols(tree.rootNode);
            return symbols.map(s => s.name).filter(Boolean);
        }
        finally {
            tree.delete();
        }
    }
    catch {
        return [];
    }
}
