UNPKG

@intlayer/chokidar

Version:

Scans and builds Intlayer declaration files into dictionaries based on Intlayer configuration.

55 lines (53 loc) 2.06 kB
import path from "node:path"; import { promises } from "node:fs"; //#region src/installLSP.ts const VSCODE_DIR = ".vscode"; const SETTINGS_FILENAME = "settings.json"; const LSP_COMMAND_KEY = "intlayer.languageServer.command"; const LSP_ARGS_KEY = "intlayer.languageServer.args"; const LSP_COMMAND_VALUE = "npx"; const LSP_ARGS_VALUE = ["@intlayer/lsp"]; /** * Writes the Intlayer LSP configuration to `.vscode/settings.json`. * Creates the file (and the `.vscode/` directory) if they don't exist. * Does not overwrite keys that are already present. * * Returns a human-readable summary of what was done plus next-step instructions. */ const installLSP = async (projectRoot) => { const settingsPath = path.join(projectRoot, VSCODE_DIR, SETTINGS_FILENAME); await promises.mkdir(path.dirname(settingsPath), { recursive: true }); let settings = {}; try { const raw = await promises.readFile(settingsPath, "utf-8"); settings = JSON.parse(raw); } catch {} const updated = []; if (!settings[LSP_COMMAND_KEY]) { settings[LSP_COMMAND_KEY] = LSP_COMMAND_VALUE; updated.push(LSP_COMMAND_KEY); } if (!settings[LSP_ARGS_KEY]) { settings[LSP_ARGS_KEY] = LSP_ARGS_VALUE; updated.push(LSP_ARGS_KEY); } await promises.writeFile(settingsPath, JSON.stringify(settings, null, 2), "utf-8"); return [ updated.length > 0 ? `Added to ${settingsPath}:\n${updated.map((k) => ` "${k}"`).join("\n")}` : `${settingsPath} already contains the LSP configuration — no changes made.`, "", "Next steps:", "", "1. Install the language server binary (required once):", " npm install -g @intlayer/lsp", "", "2. (Optional) Register the Intlayer Claude Code plugin and enable Go-to-Definition inside Claude Code:", " claude plugin marketplace add intlayer@github:aymericzip/intlayer", " claude plugin install intlayer-lsp@intlayer", " claude plugin enable intlayer-lsp@intlayer", "", "3. Reload your editor window so the new settings take effect." ].join("\n"); }; //#endregion export { installLSP }; //# sourceMappingURL=installLSP.mjs.map