The open source coding agent.
TypeScript
feat(lsp): option to disable lsps installing automatically (#1997)
Vasiliy Kulikov3706b2bca7bb
diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.tsindex 0d8bffa9ecc..1bc06cd9633 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.tsindex 4a1ddca4e63..46c52ec4590 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) returnawait Bun.spawn([BunProc.which(), "install", "@vue/language-server"], {cwd: Global.Path.bin,env: {@@ -148,6 +150,7 @@ export namespace LSPServer {if (!eslint) returnconst serverPath = path.join(Global.Path.bin, "vscode-eslint", "server", "out", "eslintServer.js")if (!(await Bun.file(serverPath).exists())) {+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) returnlog.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) returnlog.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) returnawait 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) returnlog.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) returnlog.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) returnlog.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) returnlog.info("downloading clangd from GitHub releases")const releaseResponse = await fetch("https://api.github.com/repos/clangd/clangd/releases/latest")