"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 wait(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function testDiagnosticsSimple() {
    console.log('🔧 Testing ycmd diagnostics with TypeScript errors...');
    try {
        console.log('Starting ycmd server...');
        const startResult = await (0, ycmd_1.ycmdStart)({
            workspaceRoot: process.cwd(),
            logLevel: 'debug'
        });
        if (!startResult.success) {
            throw new Error(`Failed to start server: ${startResult.message}`);
        }
        console.log('✅ ycmd server started');
        console.log('⏳ Waiting for server initialization...');
        await wait(3000);
        const testDir = path.join(process.cwd(), 'tests/ycmd/fixtures');
        const testFile = path.join(testDir, 'diagnostic_test.ts');
        if (!fs.existsSync(testDir)) {
            fs.mkdirSync(testDir, { recursive: true });
        }
        console.log('📝 Creating TypeScript file with clear errors...');
        const errorContent = `interface User {
    name: string;
    age: number;
}

function createUser(name: string, age: number): User {
    // ERROR: Missing 'age' property - should cause TypeScript error
    return { name };
}

// ERROR: Using undefined variable - should cause TypeScript error
console.log(undefinedVariable);

// ERROR: Type mismatch - missing required property
const user: User = { name: 'Alice' };

export { createUser };`;
        fs.writeFileSync(testFile, errorContent);
        console.log('🔍 Testing diagnostics (setupClient should handle notifications automatically)...');
        const diagnostics = await (0, ycmd_1.ycmdDiagnostics)({
            filepath: testFile,
            fileContents: errorContent,
            line: 1,
            column: 1
        });
        console.log('Diagnostics result:', JSON.stringify(diagnostics, null, 2));
        if (diagnostics.success && diagnostics.diagnostics && diagnostics.diagnostics.length > 0) {
            console.log(`🎉 SUCCESS: Found ${diagnostics.diagnostics.length} diagnostic(s)!`);
            diagnostics.diagnostics.forEach((diag, index) => {
                console.log(`  ${index + 1}. ${diag.kind} at line ${diag.location.line}: ${diag.text}`);
            });
        }
        else {
            console.log('❌ No diagnostics found.');
            console.log('This suggests either:');
            console.log('  1. TSServer is not processing the file correctly');
            console.log('  2. File notifications are not working as expected');
            console.log('  3. ycmd diagnostics API has an issue');
        }
        if (fs.existsSync(testFile)) {
            fs.unlinkSync(testFile);
        }
        console.log('✅ Test completed');
    }
    catch (error) {
        console.error('❌ Test failed:', error.message);
        console.error('Stack trace:', error.stack);
        process.exit(1);
    }
    process.exit(0);
}
testDiagnosticsSimple();
//# sourceMappingURL=test_diagnostics_simple.js.map