"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 ycmd_1 = require("../../../src/agents/tools/ycmd");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
async function testDiagnosticsTiming() {
    console.log('🔧 Testing ycmd diagnostics with timing...');
    try {
        console.log('Starting ycmd server...');
        const startResult = await (0, ycmd_1.ycmdStart)({
            workspaceRoot: process.cwd(),
            logLevel: 'debug'
        });
        console.log('✅ ycmd server started');
        console.log('⏳ Waiting 3 seconds for server initialization...');
        await new Promise(resolve => setTimeout(resolve, 3000));
        const testDir = path.join(process.cwd(), 'tests/ycmd/fixtures');
        const testFile = path.join(testDir, 'timing_test.ts');
        console.log('📝 Creating valid TypeScript file...');
        const validContent = `interface User {
    name: string;
    age: number;
}

function createUser(name: string, age: number): User {
    return { name, age };
}

export { createUser };`;
        fs.writeFileSync(testFile, validContent);
        console.log('🔍 Testing diagnostics on valid file...');
        let diagnostics = await (0, ycmd_1.ycmdDiagnostics)({
            filepath: testFile,
            line: 1,
            column: 1
        });
        console.log('Valid file diagnostics:', JSON.stringify(diagnostics, null, 2));
        console.log('📝 Introducing TypeScript errors...');
        const errorContent = `interface User {
    name: string;
    age: number;
}

function createUser(name: string, age: number): User {
    // This should cause an error - missing 'age' property
    return { name };
}

// This should cause an error - undefined variable
console.log(undefinedVariable);

// This should cause an error - type mismatch
const user: User = { name: 'Alice' };

export { createUser };`;
        fs.writeFileSync(testFile, errorContent);
        const delays = [500, 1000, 2000, 5000];
        for (const delay of delays) {
            console.log(`🔍 Testing diagnostics after ${delay}ms delay...`);
            await new Promise(resolve => setTimeout(resolve, delay));
            diagnostics = await (0, ycmd_1.ycmdDiagnostics)({
                filepath: testFile,
                line: 1,
                column: 1
            });
            console.log(`Diagnostics after ${delay}ms:`, JSON.stringify(diagnostics, null, 2));
            if (diagnostics.success && diagnostics.diagnostics && diagnostics.diagnostics.length > 0) {
                console.log(`✅ SUCCESS: Found ${diagnostics.diagnostics.length} diagnostic(s) after ${delay}ms!`);
                diagnostics.diagnostics.forEach((diag, index) => {
                    console.log(`  ${index + 1}. Line ${diag.location.line}: ${diag.text}`);
                });
                break;
            }
        }
        console.log('🎯 Testing specific error locations...');
        const errorLines = [8, 11, 14];
        for (const line of errorLines) {
            console.log(`Testing line ${line}...`);
            const lineDiagnostics = await (0, ycmd_1.ycmdDiagnostics)({
                filepath: testFile,
                line: line,
                column: 1
            });
            console.log(`Line ${line} diagnostics:`, JSON.stringify(lineDiagnostics, null, 2));
        }
        fs.unlinkSync(testFile);
        console.log('✅ Test completed');
        process.exit(0);
    }
    catch (error) {
        console.error('❌ Test failed:', error.message);
        process.exit(1);
    }
}
testDiagnosticsTiming();
//# sourceMappingURL=test_diagnostics_timing.js.map