import { BaseIndexer } from './base-indexer.js';
export class CSharpIndexer extends BaseIndexer {
    constructor() {
        super(...arguments);
        this.language = 'csharp';
    }
    extractExports(root, filePath) {
        const exports = [];
        const addExport = (name, type, node) => {
            exports.push({
                name,
                type,
                filePath,
                line: node.startPosition.row + 1,
                column: node.startPosition.column + 1,
                parameters: this.extractParameters(node)
            });
        };
        // 1. Classes
        const classNodes = root.descendantsOfType('class_declaration');
        for (const node of classNodes) {
            const nameNode = node.childForFieldName('name');
            if (nameNode)
                addExport(nameNode.text, 'class', node);
        }
        // 2. Methods
        const methodNodes = root.descendantsOfType('method_declaration');
        for (const node of methodNodes) {
            const nameNode = node.childForFieldName('name');
            if (nameNode)
                addExport(nameNode.text, 'method', node);
        }
        return exports;
    }
    extractImports(root) {
        const imports = {};
        // using System;
        const usingNodes = root.descendantsOfType('using_directive');
        for (const node of usingNodes) {
            const nameNode = node.childForFieldName('name');
            if (nameNode) {
                const fullPath = nameNode.text;
                const parts = fullPath.split('.');
                const localName = parts[parts.length - 1];
                if (localName)
                    imports[localName] = fullPath;
            }
        }
        return imports;
    }
    extractCalls(root) {
        const calls = [];
        const callNodes = root.descendantsOfType('invocation_expression');
        for (const node of callNodes) {
            const funcNode = node.childForFieldName('function');
            if (funcNode) {
                let name = funcNode.text;
                if (funcNode.type === 'member_access_expression') {
                    name = funcNode.childForFieldName('name')?.text || name;
                }
                const argsNode = node.childForFieldName('arguments');
                const argPositions = [];
                if (argsNode) {
                    for (let i = 0; i < argsNode.childCount; i++) {
                        const arg = argsNode.child(i);
                        if (arg && arg.isNamed && arg.text !== '(' && arg.text !== ')') {
                            argPositions.push({
                                row: arg.startPosition.row,
                                column: arg.startPosition.column
                            });
                        }
                    }
                }
                calls.push({ name, argPositions });
            }
        }
        return calls;
    }
    extractParameters(node) {
        const params = [];
        const paramNode = node.childForFieldName('parameters');
        if (paramNode) {
            const pNodes = paramNode.descendantsOfType('parameter');
            for (const p of pNodes) {
                const nameNode = p.childForFieldName('name');
                if (nameNode)
                    params.push(nameNode.text);
            }
        }
        return params;
    }
}
//# sourceMappingURL=csharp-indexer.js.map