#!/usr/bin/env tsx
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const start_1 = require("../../../src/agents/tools/ycmd/tools/start");
const diagnostics_1 = require("../../../src/agents/tools/ycmd/tools/diagnostics");
const completion_1 = require("../../../src/agents/tools/ycmd/tools/completion");
const goto_1 = require("../../../src/agents/tools/ycmd/tools/goto");
const signature_1 = require("../../../src/agents/tools/ycmd/tools/signature");
const fs = __importStar(require("fs"));
async function testYcmdTools() {
    console.log('🚀 Starting ycmd tools test...\n');
    try {
        console.log('1. Starting ycmd server...');
        const startResult = await (0, start_1.ycmdStart)({});
        console.log('Start result:', startResult);
        if (!startResult.success) {
            console.error('❌ Failed to start server');
            return;
        }
        await new Promise(resolve => setTimeout(resolve, 2000));
        const testFile = '/tmp/test_diagnostics.ts';
        const testContent = `// Test TypeScript file with errors
let message: string = 123; // Type error
let unused_variable = "test"; // Unused variable

function greet(name: string): string {
  return "Hello " + name;
}

// Missing return type and parameter type
function badFunction(param) {
  console.log(param);
  // Missing return statement
}

// Call with wrong argument type
greet(42);
`;
        fs.writeFileSync(testFile, testContent);
        console.log(`✅ Created test file: ${testFile}\n`);
        console.log('2. Testing diagnostics...');
        const diagnosticsResult = await (0, diagnostics_1.ycmdDiagnostics)({
            filepath: testFile,
            fileContents: testContent
        });
        console.log('Diagnostics result:', JSON.stringify(diagnosticsResult, null, 2));
        if (diagnosticsResult.success && diagnosticsResult.diagnostics) {
            console.log(`✅ Found ${diagnosticsResult.diagnostics.length} diagnostics`);
            diagnosticsResult.diagnostics.forEach((diag, i) => {
                console.log(`  ${i + 1}. [${diag.kind}] Line ${diag.location.line}: ${diag.text}`);
            });
        }
        else {
            console.log('❌ Diagnostics failed or returned no results');
        }
        console.log();
        console.log('3. Testing completion...');
        const completionResult = await (0, completion_1.ycmdCompletion)({
            filepath: testFile,
            contents: testContent,
            line: 5,
            column: 10
        });
        console.log('Completion result:', JSON.stringify(completionResult, null, 2));
        if (completionResult.success && completionResult.completions) {
            console.log(`✅ Found ${completionResult.completions.length} completions`);
            completionResult.completions.slice(0, 5).forEach((comp, i) => {
                console.log(`  ${i + 1}. ${comp.text} (${comp.kind})`);
            });
        }
        else {
            console.log('❌ Completion failed or returned no results');
        }
        console.log();
        console.log('4. Testing goto definition...');
        const gotoResult = await (0, goto_1.ycmdGoTo)({
            filepath: testFile,
            contents: testContent,
            line: 15,
            column: 1,
            command: 'GoTo'
        });
        console.log('Goto result:', JSON.stringify(gotoResult, null, 2));
        if (gotoResult.success && gotoResult.locations) {
            console.log(`✅ Found ${gotoResult.locations.length} goto locations`);
            gotoResult.locations.forEach((loc, i) => {
                console.log(`  ${i + 1}. ${loc.filepath}:${loc.line}:${loc.column}`);
            });
        }
        else {
            console.log('❌ Goto failed or returned no results');
        }
        console.log();
        console.log('5. Testing signature help...');
        const signatureResult = await (0, signature_1.ycmdSignatureHelp)({
            filepath: testFile,
            contents: testContent,
            line: 15,
            column: 6
        });
        console.log('Signature result:', JSON.stringify(signatureResult, null, 2));
        if (signatureResult.success && signatureResult.signatureHelp?.signatures) {
            console.log(`✅ Found ${signatureResult.signatureHelp.signatures.length} signatures`);
            signatureResult.signatureHelp.signatures.forEach((sig, i) => {
                console.log(`  ${i + 1}. ${sig.label}`);
            });
        }
        else {
            console.log('❌ Signature help failed or returned no results');
        }
        console.log('\n🎉 ycmd tools test completed!');
        process.exit(0);
    }
    catch (error) {
        console.error('❌ Test failed with error:', error);
        process.exit(1);
    }
    finally {
        try {
            fs.unlinkSync('/tmp/test_diagnostics.ts');
        }
        catch { }
    }
}
testYcmdTools().catch(console.error);
//# sourceMappingURL=test_ycmd_direct.js.map