Skip to content

Commit 3706b2b

Browse files
segoonrekram1-node
andauthored
feat(lsp): option to disable lsps installing automatically (#1997)
Co-authored-by: rekram1-node <[email protected]>
1 parent 1f57b9a commit 3706b2b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/opencode/src/flag/flag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export namespace Flag {
55
export const OPENCODE_DISABLE_AUTOUPDATE = truthy("OPENCODE_DISABLE_AUTOUPDATE")
66
export const OPENCODE_PERMISSION = process.env["OPENCODE_PERMISSION"]
77
export const OPENCODE_DISABLE_DEFAULT_PLUGINS = truthy("OPENCODE_DISABLE_DEFAULT_PLUGINS")
8+
export const OPENCODE_DISABLE_LSP_DOWNLOAD = truthy("OPENCODE_DISABLE_LSP_DOWNLOAD")
89

910
function truthy(key: string) {
1011
const value = process.env[key]?.toLowerCase()

packages/opencode/src/lsp/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BunProc } from "../bun"
77
import { $ } from "bun"
88
import fs from "fs/promises"
99
import { Filesystem } from "../util/filesystem"
10+
import { Flag } from "../flag/flag"
1011

1112
export namespace LSPServer {
1213
const log = Log.create({ service: "lsp.server" })
@@ -95,6 +96,7 @@ export namespace LSPServer {
9596
"vue-language-server.js",
9697
)
9798
if (!(await Bun.file(js).exists())) {
99+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
98100
await Bun.spawn([BunProc.which(), "install", "@vue/language-server"], {
99101
cwd: Global.Path.bin,
100102
env: {
@@ -148,6 +150,7 @@ export namespace LSPServer {
148150
if (!eslint) return
149151
const serverPath = path.join(Global.Path.bin, "vscode-eslint", "server", "out", "eslintServer.js")
150152
if (!(await Bun.file(serverPath).exists())) {
153+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
151154
log.info("downloading and building VS Code ESLint server")
152155
const response = await fetch("https://github.com/microsoft/vscode-eslint/archive/refs/heads/main.zip")
153156
if (!response.ok) return
@@ -200,6 +203,8 @@ export namespace LSPServer {
200203
})
201204
if (!bin) {
202205
if (!Bun.which("go")) return
206+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
207+
203208
log.info("installing gopls")
204209
const proc = Bun.spawn({
205210
cmd: ["go", "install", "golang.org/x/tools/gopls@latest"],
@@ -241,6 +246,7 @@ export namespace LSPServer {
241246
log.info("Ruby not found, please install Ruby first")
242247
return
243248
}
249+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
244250
log.info("installing ruby-lsp")
245251
const proc = Bun.spawn({
246252
cmd: ["gem", "install", "ruby-lsp", "--bindir", Global.Path.bin],
@@ -276,6 +282,7 @@ export namespace LSPServer {
276282
if (!binary) {
277283
const js = path.join(Global.Path.bin, "node_modules", "pyright", "dist", "pyright-langserver.js")
278284
if (!(await Bun.file(js).exists())) {
285+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
279286
await Bun.spawn([BunProc.which(), "install", "pyright"], {
280287
cwd: Global.Path.bin,
281288
env: {
@@ -323,6 +330,7 @@ export namespace LSPServer {
323330
return
324331
}
325332

333+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
326334
log.info("downloading elixir-ls from GitHub releases")
327335

328336
const response = await fetch("https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip")
@@ -372,6 +380,7 @@ export namespace LSPServer {
372380
return
373381
}
374382

383+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
375384
log.info("downloading zls from GitHub releases")
376385

377386
const releaseResponse = await fetch("https://api.github.com/repos/zigtools/zls/releases/latest")
@@ -475,6 +484,7 @@ export namespace LSPServer {
475484
return
476485
}
477486

487+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
478488
log.info("installing csharp-ls via dotnet tool")
479489
const proc = Bun.spawn({
480490
cmd: ["dotnet", "tool", "install", "csharp-ls", "--tool-path", Global.Path.bin],
@@ -527,6 +537,7 @@ export namespace LSPServer {
527537
PATH: process.env["PATH"] + ":" + Global.Path.bin,
528538
})
529539
if (!bin) {
540+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
530541
log.info("downloading clangd from GitHub releases")
531542

532543
const releaseResponse = await fetch("https://api.github.com/repos/clangd/clangd/releases/latest")

0 commit comments

Comments
 (0)