"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 });
exports.lsp = lsp;
const process = __importStar(require("process"));
const version_1 = require("../cli/version");
const explorer_1 = require("../private/explorer");
/**
 * Runs the CDK Language Server command.
 *
 * With `--features`, prints the LSP capability manifest as JSON and exits.
 * Otherwise starts the server, which speaks LSP/JSON-RPC on stdin/stdout -- in
 * that mode the command must not write anything else to stdout (CDK CLI logs go
 * to stderr, keeping the protocol channel clean). The server runs until the LSP
 * client closes the stdio channel (stdin end), then exits 0.
 */
async function lsp(options = {}) {
    // `--features` is a probe: print the capability manifest as JSON and exit
    // without starting the server, so a client can detect LSP presence and
    // features without opening a session.
    if (options.features) {
        process.stdout.write(JSON.stringify((0, explorer_1.cdkLspManifest)((0, version_1.versionNumber)())) + '\n');
        return 0;
    }
    (0, explorer_1.startLspServer)((0, version_1.versionNumber)());
    await new Promise((resolve) => {
        const done = () => resolve();
        process.stdin.once('end', done);
        process.stdin.once('close', done);
    });
    return 0;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibHNwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsibHNwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBYUEsa0JBa0JDO0FBL0JELGlEQUFtQztBQUNuQyw0Q0FBK0M7QUFDL0Msa0RBQXFFO0FBRXJFOzs7Ozs7OztHQVFHO0FBQ0ksS0FBSyxVQUFVLEdBQUcsQ0FBQyxVQUEyQyxFQUFFO0lBQ3JFLDBFQUEwRTtJQUMxRSx1RUFBdUU7SUFDdkUsc0NBQXNDO0lBQ3RDLElBQUksT0FBTyxDQUFDLFFBQVEsRUFBRSxDQUFDO1FBQ3JCLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBQSx5QkFBYyxFQUFDLElBQUEsdUJBQWEsR0FBRSxDQUFDLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQztRQUM3RSxPQUFPLENBQUMsQ0FBQztJQUNYLENBQUM7SUFFRCxJQUFBLHlCQUFjLEVBQUMsSUFBQSx1QkFBYSxHQUFFLENBQUMsQ0FBQztJQUVoQyxNQUFNLElBQUksT0FBTyxDQUFPLENBQUMsT0FBTyxFQUFFLEVBQUU7UUFDbEMsTUFBTSxJQUFJLEdBQUcsR0FBRyxFQUFFLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDN0IsT0FBTyxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsS0FBSyxFQUFFLElBQUksQ0FBQyxDQUFDO1FBQ2hDLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRSxJQUFJLENBQUMsQ0F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