"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 cdk_explorer_1 = require("@aws-cdk/cdk-explorer");
const version_1 = require("../cli/version");
/**
 * 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, cdk_explorer_1.cdkLspManifest)((0, version_1.versionNumber)())) + '\n');
        return 0;
    }
    (0, cdk_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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibHNwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsibHNwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBYUEsa0JBa0JDO0FBL0JELGlEQUFtQztBQUNuQyx3REFBdUU7QUFDdkUsNENBQStDO0FBRS9DOzs7Ozs7OztHQVFHO0FBQ0ksS0FBSyxVQUFVLEdBQUcsQ0FBQyxVQUEyQyxFQUFFO0lBQ3JFLDBFQUEwRTtJQUMxRSx1RUFBdUU7SUFDdkUsc0NBQXNDO0lBQ3RDLElBQUksT0FBTyxDQUFDLFFBQVEsRUFBRSxDQUFDO1FBQ3JCLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBQSw2QkFBYyxFQUFDLElBQUEsdUJBQWEsR0FBRSxDQUFDLENBQUMsR0FBRyxJQUFJLENBQUMsQ0FBQztRQUM3RSxPQUFPLENBQUMsQ0FBQztJQUNYLENBQUM7SUFFRCxJQUFBLDZCQUFjLEVBQUMsSUFBQSx1QkFBYSxHQUFFLENBQUMsQ0FBQztJQUVoQyxNQUFNLElBQUksT0FBTyxDQUFPLENBQUMsT0FBTyxFQUFFLEVBQUU7UUFDbEMsTUFBTSxJQUFJLEdBQUcsR0FBRyxFQUFFLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDN0IsT0FBTyxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsS0FBSyxFQUFFLElBQUksQ0FBQyxDQUFDO1FBQ2hDLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE9BQU8sRUFBRS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