import lspExtension from "../node_modules/pi-lsp/extensions/pi-lsp/index.ts";
import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { fileURLToPath } from "node:url";
import { deployBundleLspConfig } from "./lsp-config.ts";

const TYPESCRIPT_LANGUAGE_SERVER_CLI = fileURLToPath(
	new URL("../node_modules/typescript-language-server/lib/cli.mjs", import.meta.url),
);

/** Deploy the bundle-owned LSP config before registering pi-lsp. */
export default function bundledLspExtension(pi: ExtensionAPI): void {
	deployBundleLspConfig(getAgentDir(), {
		nodeBinary: process.execPath,
		serverCliPath: TYPESCRIPT_LANGUAGE_SERVER_CLI,
	});
	lspExtension(pi);
}
