diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts index 0d8bffa9ec..1bc06cd963 100644 --- a/packages/opencode/src/flag/flag.ts +++ b/packages/opencode/src/flag/flag.ts @@ -5,6 +5,7 @@ export namespace Flag { export const OPENCODE_DISABLE_AUTOUPDATE = truthy("OPENCODE_DISABLE_AUTOUPDATE") export const OPENCODE_PERMISSION = process.env["OPENCODE_PERMISSION"] export const OPENCODE_DISABLE_DEFAULT_PLUGINS = truthy("OPENCODE_DISABLE_DEFAULT_PLUGINS") + export const OPENCODE_DISABLE_LSP_DOWNLOAD = truthy("OPENCODE_DISABLE_LSP_DOWNLOAD") function truthy(key: string) { const value = process.env[key]?.toLowerCase() diff --git a/packages/opencode/src/lsp/server.ts b/packages/opencode/src/lsp/server.ts index 4a1ddca4e6..46c52ec459 100644 --- a/packages/opencode/src/lsp/server.ts +++ b/packages/opencode/src/lsp/server.ts @@ -7,6 +7,7 @@ import { BunProc } from "../bun" import { $ } from "bun" import fs from "fs/promises" import { Filesystem } from "../util/filesystem" +import { Flag } from "../flag/flag" export namespace LSPServer { const log = Log.create({ service: "lsp.server" }) @@ -95,6 +96,7 @@ export namespace LSPServer { "vue-language-server.js", ) if (!(await Bun.file(js).exists())) { + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return await Bun.spawn([BunProc.which(), "install", "@vue/language-server"], { cwd: Global.Path.bin, env: { @@ -148,6 +150,7 @@ export namespace LSPServer { if (!eslint) return const serverPath = path.join(Global.Path.bin, "vscode-eslint", "server", "out", "eslintServer.js") if (!(await Bun.file(serverPath).exists())) { + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("downloading and building VS Code ESLint server") const response = await fetch("https://github.com/microsoft/vscode-eslint/archive/refs/heads/main.zip") if (!response.ok) return @@ -200,6 +203,8 @@ export namespace LSPServer { }) if (!bin) { if (!Bun.which("go")) return + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return + log.info("installing gopls") const proc = Bun.spawn({ cmd: ["go", "install", "golang.org/x/tools/gopls@latest"], @@ -241,6 +246,7 @@ export namespace LSPServer { log.info("Ruby not found, please install Ruby first") return } + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("installing ruby-lsp") const proc = Bun.spawn({ cmd: ["gem", "install", "ruby-lsp", "--bindir", Global.Path.bin], @@ -276,6 +282,7 @@ export namespace LSPServer { if (!binary) { const js = path.join(Global.Path.bin, "node_modules", "pyright", "dist", "pyright-langserver.js") if (!(await Bun.file(js).exists())) { + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return await Bun.spawn([BunProc.which(), "install", "pyright"], { cwd: Global.Path.bin, env: { @@ -323,6 +330,7 @@ export namespace LSPServer { return } + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("downloading elixir-ls from GitHub releases") const response = await fetch("https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip") @@ -372,6 +380,7 @@ export namespace LSPServer { return } + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("downloading zls from GitHub releases") const releaseResponse = await fetch("https://api.github.com/repos/zigtools/zls/releases/latest") @@ -475,6 +484,7 @@ export namespace LSPServer { return } + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("installing csharp-ls via dotnet tool") const proc = Bun.spawn({ cmd: ["dotnet", "tool", "install", "csharp-ls", "--tool-path", Global.Path.bin], @@ -527,6 +537,7 @@ export namespace LSPServer { PATH: process.env["PATH"] + ":" + Global.Path.bin, }) if (!bin) { + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return log.info("downloading clangd from GitHub releases") const releaseResponse = await fetch("https://api.github.com/repos/clangd/clangd/releases/latest")