chad-code 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/README.md +55 -6
  2. package/package.json +36 -98
  3. package/AGENTS.md +0 -27
  4. package/Dockerfile +0 -18
  5. package/README.npm.md +0 -64
  6. package/bunfig.toml +0 -7
  7. package/eslint.config.js +0 -29
  8. package/parsers-config.ts +0 -253
  9. package/script/build.ts +0 -167
  10. package/script/publish-registries.ts +0 -187
  11. package/script/publish.ts +0 -93
  12. package/script/schema.ts +0 -47
  13. package/src/acp/README.md +0 -164
  14. package/src/acp/agent.ts +0 -1086
  15. package/src/acp/session.ts +0 -101
  16. package/src/acp/types.ts +0 -22
  17. package/src/agent/agent.ts +0 -253
  18. package/src/agent/generate.txt +0 -75
  19. package/src/agent/prompt/compaction.txt +0 -12
  20. package/src/agent/prompt/explore.txt +0 -18
  21. package/src/agent/prompt/summary.txt +0 -11
  22. package/src/agent/prompt/title.txt +0 -36
  23. package/src/auth/index.ts +0 -70
  24. package/src/bun/index.ts +0 -130
  25. package/src/bus/bus-event.ts +0 -43
  26. package/src/bus/global.ts +0 -10
  27. package/src/bus/index.ts +0 -105
  28. package/src/cli/bootstrap.ts +0 -17
  29. package/src/cli/cmd/acp.ts +0 -69
  30. package/src/cli/cmd/agent.ts +0 -257
  31. package/src/cli/cmd/auth.ts +0 -132
  32. package/src/cli/cmd/cmd.ts +0 -7
  33. package/src/cli/cmd/debug/agent.ts +0 -28
  34. package/src/cli/cmd/debug/config.ts +0 -15
  35. package/src/cli/cmd/debug/file.ts +0 -91
  36. package/src/cli/cmd/debug/index.ts +0 -45
  37. package/src/cli/cmd/debug/lsp.ts +0 -48
  38. package/src/cli/cmd/debug/ripgrep.ts +0 -83
  39. package/src/cli/cmd/debug/scrap.ts +0 -15
  40. package/src/cli/cmd/debug/skill.ts +0 -15
  41. package/src/cli/cmd/debug/snapshot.ts +0 -48
  42. package/src/cli/cmd/export.ts +0 -88
  43. package/src/cli/cmd/generate.ts +0 -38
  44. package/src/cli/cmd/github.ts +0 -32
  45. package/src/cli/cmd/import.ts +0 -98
  46. package/src/cli/cmd/mcp.ts +0 -670
  47. package/src/cli/cmd/models.ts +0 -42
  48. package/src/cli/cmd/pr.ts +0 -112
  49. package/src/cli/cmd/run.ts +0 -374
  50. package/src/cli/cmd/serve.ts +0 -16
  51. package/src/cli/cmd/session.ts +0 -135
  52. package/src/cli/cmd/stats.ts +0 -402
  53. package/src/cli/cmd/tui/app.tsx +0 -705
  54. package/src/cli/cmd/tui/attach.ts +0 -32
  55. package/src/cli/cmd/tui/component/border.tsx +0 -21
  56. package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
  57. package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
  58. package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
  59. package/src/cli/cmd/tui/component/dialog-model.tsx +0 -232
  60. package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -228
  61. package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -115
  62. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
  63. package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -86
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +0 -162
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
  67. package/src/cli/cmd/tui/component/did-you-know.tsx +0 -85
  68. package/src/cli/cmd/tui/component/logo.tsx +0 -43
  69. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -654
  70. package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
  71. package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1078
  72. package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
  73. package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
  74. package/src/cli/cmd/tui/component/tips.ts +0 -92
  75. package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
  76. package/src/cli/cmd/tui/context/args.tsx +0 -14
  77. package/src/cli/cmd/tui/context/directory.ts +0 -13
  78. package/src/cli/cmd/tui/context/exit.tsx +0 -23
  79. package/src/cli/cmd/tui/context/helper.tsx +0 -25
  80. package/src/cli/cmd/tui/context/keybind.tsx +0 -101
  81. package/src/cli/cmd/tui/context/kv.tsx +0 -49
  82. package/src/cli/cmd/tui/context/local.tsx +0 -392
  83. package/src/cli/cmd/tui/context/prompt.tsx +0 -18
  84. package/src/cli/cmd/tui/context/route.tsx +0 -46
  85. package/src/cli/cmd/tui/context/sdk.tsx +0 -75
  86. package/src/cli/cmd/tui/context/sync.tsx +0 -384
  87. package/src/cli/cmd/tui/context/theme/aura.json +0 -69
  88. package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
  89. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
  90. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
  91. package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
  92. package/src/cli/cmd/tui/context/theme/chad.json +0 -245
  93. package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
  94. package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
  95. package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
  96. package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
  97. package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
  98. package/src/cli/cmd/tui/context/theme/github.json +0 -233
  99. package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
  100. package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
  101. package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -227
  102. package/src/cli/cmd/tui/context/theme/material.json +0 -235
  103. package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
  104. package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
  105. package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
  106. package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
  107. package/src/cli/cmd/tui/context/theme/nord.json +0 -223
  108. package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
  109. package/src/cli/cmd/tui/context/theme/orng.json +0 -245
  110. package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
  111. package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
  112. package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
  113. package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
  114. package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
  115. package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
  116. package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
  117. package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
  118. package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
  119. package/src/cli/cmd/tui/context/theme.tsx +0 -1137
  120. package/src/cli/cmd/tui/event.ts +0 -46
  121. package/src/cli/cmd/tui/routes/home.tsx +0 -138
  122. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
  123. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
  124. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
  125. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
  126. package/src/cli/cmd/tui/routes/session/footer.tsx +0 -88
  127. package/src/cli/cmd/tui/routes/session/header.tsx +0 -125
  128. package/src/cli/cmd/tui/routes/session/index.tsx +0 -1814
  129. package/src/cli/cmd/tui/routes/session/permission.tsx +0 -416
  130. package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -318
  131. package/src/cli/cmd/tui/spawn.ts +0 -48
  132. package/src/cli/cmd/tui/thread.ts +0 -111
  133. package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
  134. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
  135. package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
  136. package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
  137. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
  138. package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -345
  139. package/src/cli/cmd/tui/ui/dialog.tsx +0 -171
  140. package/src/cli/cmd/tui/ui/link.tsx +0 -28
  141. package/src/cli/cmd/tui/ui/spinner.ts +0 -368
  142. package/src/cli/cmd/tui/ui/toast.tsx +0 -100
  143. package/src/cli/cmd/tui/util/clipboard.ts +0 -127
  144. package/src/cli/cmd/tui/util/editor.ts +0 -32
  145. package/src/cli/cmd/tui/util/signal.ts +0 -7
  146. package/src/cli/cmd/tui/util/terminal.ts +0 -114
  147. package/src/cli/cmd/tui/util/transcript.ts +0 -98
  148. package/src/cli/cmd/tui/worker.ts +0 -68
  149. package/src/cli/cmd/uninstall.ts +0 -344
  150. package/src/cli/cmd/upgrade.ts +0 -67
  151. package/src/cli/cmd/web.ts +0 -73
  152. package/src/cli/error.ts +0 -56
  153. package/src/cli/network.ts +0 -53
  154. package/src/cli/ui.ts +0 -87
  155. package/src/cli/upgrade.ts +0 -25
  156. package/src/command/index.ts +0 -131
  157. package/src/command/template/initialize.txt +0 -10
  158. package/src/command/template/review.txt +0 -97
  159. package/src/config/config.ts +0 -1124
  160. package/src/config/markdown.ts +0 -41
  161. package/src/env/index.ts +0 -26
  162. package/src/file/ignore.ts +0 -83
  163. package/src/file/index.ts +0 -411
  164. package/src/file/ripgrep.ts +0 -402
  165. package/src/file/time.ts +0 -64
  166. package/src/file/watcher.ts +0 -117
  167. package/src/flag/flag.ts +0 -52
  168. package/src/format/formatter.ts +0 -359
  169. package/src/format/index.ts +0 -137
  170. package/src/global/index.ts +0 -55
  171. package/src/id/id.ts +0 -73
  172. package/src/ide/index.ts +0 -77
  173. package/src/index.ts +0 -159
  174. package/src/installation/index.ts +0 -198
  175. package/src/lsp/client.ts +0 -252
  176. package/src/lsp/index.ts +0 -485
  177. package/src/lsp/language.ts +0 -119
  178. package/src/lsp/server.ts +0 -2023
  179. package/src/mcp/auth.ts +0 -135
  180. package/src/mcp/index.ts +0 -874
  181. package/src/mcp/oauth-callback.ts +0 -200
  182. package/src/mcp/oauth-provider.ts +0 -154
  183. package/src/patch/index.ts +0 -622
  184. package/src/permission/arity.ts +0 -163
  185. package/src/permission/index.ts +0 -210
  186. package/src/permission/next.ts +0 -268
  187. package/src/plugin/index.ts +0 -106
  188. package/src/project/bootstrap.ts +0 -31
  189. package/src/project/instance.ts +0 -78
  190. package/src/project/project.ts +0 -263
  191. package/src/project/state.ts +0 -65
  192. package/src/project/vcs.ts +0 -76
  193. package/src/provider/auth.ts +0 -143
  194. package/src/provider/models-macro.ts +0 -4
  195. package/src/provider/models.ts +0 -77
  196. package/src/provider/provider.ts +0 -516
  197. package/src/provider/transform.ts +0 -114
  198. package/src/pty/index.ts +0 -212
  199. package/src/server/error.ts +0 -36
  200. package/src/server/mdns.ts +0 -57
  201. package/src/server/project.ts +0 -79
  202. package/src/server/server.ts +0 -2866
  203. package/src/server/tui.ts +0 -71
  204. package/src/session/compaction.ts +0 -225
  205. package/src/session/index.ts +0 -469
  206. package/src/session/llm.ts +0 -213
  207. package/src/session/message-v2.ts +0 -742
  208. package/src/session/message.ts +0 -189
  209. package/src/session/processor.ts +0 -402
  210. package/src/session/prompt/anthropic-20250930.txt +0 -166
  211. package/src/session/prompt/anthropic.txt +0 -105
  212. package/src/session/prompt/anthropic_spoof.txt +0 -1
  213. package/src/session/prompt/beast.txt +0 -147
  214. package/src/session/prompt/build-switch.txt +0 -5
  215. package/src/session/prompt/codex.txt +0 -318
  216. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  217. package/src/session/prompt/gemini.txt +0 -155
  218. package/src/session/prompt/max-steps.txt +0 -16
  219. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  220. package/src/session/prompt/plan.txt +0 -26
  221. package/src/session/prompt/qwen.txt +0 -109
  222. package/src/session/prompt.ts +0 -1621
  223. package/src/session/retry.ts +0 -90
  224. package/src/session/revert.ts +0 -108
  225. package/src/session/status.ts +0 -76
  226. package/src/session/summary.ts +0 -194
  227. package/src/session/system.ts +0 -108
  228. package/src/session/todo.ts +0 -37
  229. package/src/share/share-next.ts +0 -194
  230. package/src/share/share.ts +0 -23
  231. package/src/shell/shell.ts +0 -67
  232. package/src/skill/index.ts +0 -1
  233. package/src/skill/skill.ts +0 -124
  234. package/src/snapshot/index.ts +0 -197
  235. package/src/storage/storage.ts +0 -226
  236. package/src/tool/bash.ts +0 -262
  237. package/src/tool/bash.txt +0 -116
  238. package/src/tool/batch.ts +0 -175
  239. package/src/tool/batch.txt +0 -24
  240. package/src/tool/codesearch.ts +0 -132
  241. package/src/tool/codesearch.txt +0 -12
  242. package/src/tool/edit.ts +0 -655
  243. package/src/tool/edit.txt +0 -10
  244. package/src/tool/glob.ts +0 -75
  245. package/src/tool/glob.txt +0 -6
  246. package/src/tool/grep.ts +0 -132
  247. package/src/tool/grep.txt +0 -8
  248. package/src/tool/invalid.ts +0 -17
  249. package/src/tool/ls.ts +0 -119
  250. package/src/tool/ls.txt +0 -1
  251. package/src/tool/lsp.ts +0 -94
  252. package/src/tool/lsp.txt +0 -19
  253. package/src/tool/multiedit.ts +0 -46
  254. package/src/tool/multiedit.txt +0 -41
  255. package/src/tool/patch.ts +0 -210
  256. package/src/tool/patch.txt +0 -1
  257. package/src/tool/read.ts +0 -191
  258. package/src/tool/read.txt +0 -12
  259. package/src/tool/registry.ts +0 -137
  260. package/src/tool/skill.ts +0 -77
  261. package/src/tool/task.ts +0 -167
  262. package/src/tool/task.txt +0 -60
  263. package/src/tool/todo.ts +0 -53
  264. package/src/tool/todoread.txt +0 -14
  265. package/src/tool/todowrite.txt +0 -167
  266. package/src/tool/tool.ts +0 -73
  267. package/src/tool/webfetch.ts +0 -182
  268. package/src/tool/webfetch.txt +0 -13
  269. package/src/tool/websearch.ts +0 -144
  270. package/src/tool/websearch.txt +0 -11
  271. package/src/tool/write.ts +0 -84
  272. package/src/tool/write.txt +0 -8
  273. package/src/util/archive.ts +0 -16
  274. package/src/util/color.ts +0 -19
  275. package/src/util/context.ts +0 -25
  276. package/src/util/defer.ts +0 -12
  277. package/src/util/eventloop.ts +0 -20
  278. package/src/util/filesystem.ts +0 -83
  279. package/src/util/fn.ts +0 -11
  280. package/src/util/iife.ts +0 -3
  281. package/src/util/keybind.ts +0 -102
  282. package/src/util/lazy.ts +0 -18
  283. package/src/util/locale.ts +0 -81
  284. package/src/util/lock.ts +0 -98
  285. package/src/util/log.ts +0 -180
  286. package/src/util/queue.ts +0 -32
  287. package/src/util/rpc.ts +0 -42
  288. package/src/util/scrap.ts +0 -10
  289. package/src/util/signal.ts +0 -12
  290. package/src/util/timeout.ts +0 -14
  291. package/src/util/token.ts +0 -7
  292. package/src/util/wildcard.ts +0 -54
  293. package/src/worktree/index.ts +0 -217
  294. package/sst-env.d.ts +0 -9
  295. package/test/agent/agent.test.ts +0 -448
  296. package/test/bun.test.ts +0 -53
  297. package/test/cli/github-action.test.ts +0 -129
  298. package/test/cli/github-remote.test.ts +0 -80
  299. package/test/cli/tui/transcript.test.ts +0 -297
  300. package/test/config/agent-color.test.ts +0 -66
  301. package/test/config/config.test.ts +0 -870
  302. package/test/config/markdown.test.ts +0 -89
  303. package/test/file/ignore.test.ts +0 -10
  304. package/test/file/path-traversal.test.ts +0 -115
  305. package/test/fixture/fixture.ts +0 -45
  306. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  307. package/test/ide/ide.test.ts +0 -82
  308. package/test/keybind.test.ts +0 -421
  309. package/test/lsp/client.test.ts +0 -95
  310. package/test/mcp/headers.test.ts +0 -153
  311. package/test/patch/patch.test.ts +0 -348
  312. package/test/permission/arity.test.ts +0 -33
  313. package/test/permission/next.test.ts +0 -652
  314. package/test/preload.ts +0 -63
  315. package/test/project/project.test.ts +0 -120
  316. package/test/provider/amazon-bedrock.test.ts +0 -236
  317. package/test/provider/provider.test.ts +0 -2127
  318. package/test/provider/transform.test.ts +0 -980
  319. package/test/server/session-select.test.ts +0 -78
  320. package/test/session/compaction.test.ts +0 -251
  321. package/test/session/message-v2.test.ts +0 -570
  322. package/test/session/retry.test.ts +0 -131
  323. package/test/session/revert-compact.test.ts +0 -285
  324. package/test/session/session.test.ts +0 -71
  325. package/test/skill/skill.test.ts +0 -185
  326. package/test/snapshot/snapshot.test.ts +0 -939
  327. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  328. package/test/tool/bash.test.ts +0 -232
  329. package/test/tool/grep.test.ts +0 -109
  330. package/test/tool/patch.test.ts +0 -261
  331. package/test/tool/read.test.ts +0 -167
  332. package/test/util/iife.test.ts +0 -36
  333. package/test/util/lazy.test.ts +0 -50
  334. package/test/util/timeout.test.ts +0 -21
  335. package/test/util/wildcard.test.ts +0 -55
  336. package/tsconfig.json +0 -16
  337. /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
package/src/lsp/server.ts DELETED
@@ -1,2023 +0,0 @@
1
- import { spawn, type ChildProcessWithoutNullStreams } from "child_process"
2
- import path from "path"
3
- import os from "os"
4
- import { Global } from "../global"
5
- import { Log } from "../util/log"
6
- import { BunProc } from "../bun"
7
- import { $, readableStreamToText } from "bun"
8
- import fs from "fs/promises"
9
- import { Filesystem } from "../util/filesystem"
10
- import { Instance } from "../project/instance"
11
- import { Flag } from "../flag/flag"
12
- import { Archive } from "../util/archive"
13
-
14
- export namespace LSPServer {
15
- const log = Log.create({ service: "lsp.server" })
16
-
17
- export interface Handle {
18
- process: ChildProcessWithoutNullStreams
19
- initialization?: Record<string, any>
20
- }
21
-
22
- type RootFunction = (file: string) => Promise<string | undefined>
23
-
24
- const NearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => {
25
- return async (file) => {
26
- if (excludePatterns) {
27
- const excludedFiles = Filesystem.up({
28
- targets: excludePatterns,
29
- start: path.dirname(file),
30
- stop: Instance.directory,
31
- })
32
- const excluded = await excludedFiles.next()
33
- await excludedFiles.return()
34
- if (excluded.value) return undefined
35
- }
36
- const files = Filesystem.up({
37
- targets: includePatterns,
38
- start: path.dirname(file),
39
- stop: Instance.directory,
40
- })
41
- const first = await files.next()
42
- await files.return()
43
- if (!first.value) return Instance.directory
44
- return path.dirname(first.value)
45
- }
46
- }
47
-
48
- export interface Info {
49
- id: string
50
- extensions: string[]
51
- global?: boolean
52
- root: RootFunction
53
- spawn(root: string): Promise<Handle | undefined>
54
- }
55
-
56
- export const Deno: Info = {
57
- id: "deno",
58
- root: async (file) => {
59
- const files = Filesystem.up({
60
- targets: ["deno.json", "deno.jsonc"],
61
- start: path.dirname(file),
62
- stop: Instance.directory,
63
- })
64
- const first = await files.next()
65
- await files.return()
66
- if (!first.value) return undefined
67
- return path.dirname(first.value)
68
- },
69
- extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
70
- async spawn(root) {
71
- const deno = Bun.which("deno")
72
- if (!deno) {
73
- log.info("deno not found, please install deno first")
74
- return
75
- }
76
- return {
77
- process: spawn(deno, ["lsp"], {
78
- cwd: root,
79
- }),
80
- }
81
- },
82
- }
83
-
84
- export const Typescript: Info = {
85
- id: "typescript",
86
- root: NearestRoot(
87
- ["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"],
88
- ["deno.json", "deno.jsonc"],
89
- ),
90
- extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
91
- async spawn(root) {
92
- const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})
93
- log.info("typescript server", { tsserver })
94
- if (!tsserver) return
95
- const proc = spawn(BunProc.which(), ["x", "typescript-language-server", "--stdio"], {
96
- cwd: root,
97
- env: {
98
- ...process.env,
99
- BUN_BE_BUN: "1",
100
- },
101
- })
102
- return {
103
- process: proc,
104
- initialization: {
105
- tsserver: {
106
- path: tsserver,
107
- },
108
- },
109
- }
110
- },
111
- }
112
-
113
- export const Vue: Info = {
114
- id: "vue",
115
- extensions: [".vue"],
116
- root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
117
- async spawn(root) {
118
- let binary = Bun.which("vue-language-server")
119
- const args: string[] = []
120
- if (!binary) {
121
- const js = path.join(
122
- Global.Path.bin,
123
- "node_modules",
124
- "@vue",
125
- "language-server",
126
- "bin",
127
- "vue-language-server.js",
128
- )
129
- if (!(await Bun.file(js).exists())) {
130
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
131
- await Bun.spawn([BunProc.which(), "install", "@vue/language-server"], {
132
- cwd: Global.Path.bin,
133
- env: {
134
- ...process.env,
135
- BUN_BE_BUN: "1",
136
- },
137
- stdout: "pipe",
138
- stderr: "pipe",
139
- stdin: "pipe",
140
- }).exited
141
- }
142
- binary = BunProc.which()
143
- args.push("run", js)
144
- }
145
- args.push("--stdio")
146
- const proc = spawn(binary, args, {
147
- cwd: root,
148
- env: {
149
- ...process.env,
150
- BUN_BE_BUN: "1",
151
- },
152
- })
153
- return {
154
- process: proc,
155
- initialization: {
156
- // Leave empty; the server will auto-detect workspace TypeScript.
157
- },
158
- }
159
- },
160
- }
161
-
162
- export const ESLint: Info = {
163
- id: "eslint",
164
- root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
165
- extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue"],
166
- async spawn(root) {
167
- const eslint = await Bun.resolve("eslint", Instance.directory).catch(() => {})
168
- if (!eslint) return
169
- log.info("spawning eslint server")
170
- const serverPath = path.join(Global.Path.bin, "vscode-eslint", "server", "out", "eslintServer.js")
171
- if (!(await Bun.file(serverPath).exists())) {
172
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
173
- log.info("downloading and building VS Code ESLint server")
174
- const response = await fetch("https://github.com/microsoft/vscode-eslint/archive/refs/heads/main.zip")
175
- if (!response.ok) return
176
-
177
- const zipPath = path.join(Global.Path.bin, "vscode-eslint.zip")
178
- await Bun.file(zipPath).write(response)
179
-
180
- const ok = await Archive.extractZip(zipPath, Global.Path.bin)
181
- .then(() => true)
182
- .catch((error) => {
183
- log.error("Failed to extract vscode-eslint archive", { error })
184
- return false
185
- })
186
- if (!ok) return
187
- await fs.rm(zipPath, { force: true })
188
-
189
- const extractedPath = path.join(Global.Path.bin, "vscode-eslint-main")
190
- const finalPath = path.join(Global.Path.bin, "vscode-eslint")
191
-
192
- const stats = await fs.stat(finalPath).catch(() => undefined)
193
- if (stats) {
194
- log.info("removing old eslint installation", { path: finalPath })
195
- await fs.rm(finalPath, { force: true, recursive: true })
196
- }
197
- await fs.rename(extractedPath, finalPath)
198
-
199
- const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
200
- await $`${npmCmd} install`.cwd(finalPath).quiet()
201
- await $`${npmCmd} run compile`.cwd(finalPath).quiet()
202
-
203
- log.info("installed VS Code ESLint server", { serverPath })
204
- }
205
-
206
- const proc = spawn(BunProc.which(), [serverPath, "--stdio"], {
207
- cwd: root,
208
- env: {
209
- ...process.env,
210
- BUN_BE_BUN: "1",
211
- },
212
- })
213
-
214
- return {
215
- process: proc,
216
- }
217
- },
218
- }
219
-
220
- export const Oxlint: Info = {
221
- id: "oxlint",
222
- root: NearestRoot([
223
- ".oxlintrc.json",
224
- "package-lock.json",
225
- "bun.lockb",
226
- "bun.lock",
227
- "pnpm-lock.yaml",
228
- "yarn.lock",
229
- "package.json",
230
- ]),
231
- extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"],
232
- async spawn(root) {
233
- const ext = process.platform === "win32" ? ".cmd" : ""
234
-
235
- const serverTarget = path.join("node_modules", ".bin", "oxc_language_server" + ext)
236
- const lintTarget = path.join("node_modules", ".bin", "oxlint" + ext)
237
-
238
- const resolveBin = async (target: string) => {
239
- const localBin = path.join(root, target)
240
- if (await Bun.file(localBin).exists()) return localBin
241
-
242
- const candidates = Filesystem.up({
243
- targets: [target],
244
- start: root,
245
- stop: Instance.worktree,
246
- })
247
- const first = await candidates.next()
248
- await candidates.return()
249
- if (first.value) return first.value
250
-
251
- return undefined
252
- }
253
-
254
- let lintBin = await resolveBin(lintTarget)
255
- if (!lintBin) {
256
- const found = Bun.which("oxlint")
257
- if (found) lintBin = found
258
- }
259
-
260
- if (lintBin) {
261
- const proc = Bun.spawn([lintBin, "--help"], { stdout: "pipe" })
262
- await proc.exited
263
- const help = await readableStreamToText(proc.stdout)
264
- if (help.includes("--lsp")) {
265
- return {
266
- process: spawn(lintBin, ["--lsp"], {
267
- cwd: root,
268
- }),
269
- }
270
- }
271
- }
272
-
273
- let serverBin = await resolveBin(serverTarget)
274
- if (!serverBin) {
275
- const found = Bun.which("oxc_language_server")
276
- if (found) serverBin = found
277
- }
278
- if (serverBin) {
279
- return {
280
- process: spawn(serverBin, [], {
281
- cwd: root,
282
- }),
283
- }
284
- }
285
-
286
- log.info("oxlint not found, please install oxlint")
287
- return
288
- },
289
- }
290
-
291
- export const Biome: Info = {
292
- id: "biome",
293
- root: NearestRoot([
294
- "biome.json",
295
- "biome.jsonc",
296
- "package-lock.json",
297
- "bun.lockb",
298
- "bun.lock",
299
- "pnpm-lock.yaml",
300
- "yarn.lock",
301
- ]),
302
- extensions: [
303
- ".ts",
304
- ".tsx",
305
- ".js",
306
- ".jsx",
307
- ".mjs",
308
- ".cjs",
309
- ".mts",
310
- ".cts",
311
- ".json",
312
- ".jsonc",
313
- ".vue",
314
- ".astro",
315
- ".svelte",
316
- ".css",
317
- ".graphql",
318
- ".gql",
319
- ".html",
320
- ],
321
- async spawn(root) {
322
- const localBin = path.join(root, "node_modules", ".bin", "biome")
323
- let bin: string | undefined
324
- if (await Bun.file(localBin).exists()) bin = localBin
325
- if (!bin) {
326
- const found = Bun.which("biome")
327
- if (found) bin = found
328
- }
329
-
330
- let args = ["lsp-proxy", "--stdio"]
331
-
332
- if (!bin) {
333
- const resolved = await Bun.resolve("biome", root).catch(() => undefined)
334
- if (!resolved) return
335
- bin = BunProc.which()
336
- args = ["x", "biome", "lsp-proxy", "--stdio"]
337
- }
338
-
339
- const proc = spawn(bin, args, {
340
- cwd: root,
341
- env: {
342
- ...process.env,
343
- BUN_BE_BUN: "1",
344
- },
345
- })
346
-
347
- return {
348
- process: proc,
349
- }
350
- },
351
- }
352
-
353
- export const Gopls: Info = {
354
- id: "gopls",
355
- root: async (file) => {
356
- const work = await NearestRoot(["go.work"])(file)
357
- if (work) return work
358
- return NearestRoot(["go.mod", "go.sum"])(file)
359
- },
360
- extensions: [".go"],
361
- async spawn(root) {
362
- let bin = Bun.which("gopls", {
363
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
364
- })
365
- if (!bin) {
366
- if (!Bun.which("go")) return
367
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
368
-
369
- log.info("installing gopls")
370
- const proc = Bun.spawn({
371
- cmd: ["go", "install", "golang.org/x/tools/gopls@latest"],
372
- env: { ...process.env, GOBIN: Global.Path.bin },
373
- stdout: "pipe",
374
- stderr: "pipe",
375
- stdin: "pipe",
376
- })
377
- const exit = await proc.exited
378
- if (exit !== 0) {
379
- log.error("Failed to install gopls")
380
- return
381
- }
382
- bin = path.join(Global.Path.bin, "gopls" + (process.platform === "win32" ? ".exe" : ""))
383
- log.info(`installed gopls`, {
384
- bin,
385
- })
386
- }
387
- return {
388
- process: spawn(bin!, {
389
- cwd: root,
390
- }),
391
- }
392
- },
393
- }
394
-
395
- export const Rubocop: Info = {
396
- id: "ruby-lsp",
397
- root: NearestRoot(["Gemfile"]),
398
- extensions: [".rb", ".rake", ".gemspec", ".ru"],
399
- async spawn(root) {
400
- let bin = Bun.which("rubocop", {
401
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
402
- })
403
- if (!bin) {
404
- const ruby = Bun.which("ruby")
405
- const gem = Bun.which("gem")
406
- if (!ruby || !gem) {
407
- log.info("Ruby not found, please install Ruby first")
408
- return
409
- }
410
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
411
- log.info("installing rubocop")
412
- const proc = Bun.spawn({
413
- cmd: ["gem", "install", "rubocop", "--bindir", Global.Path.bin],
414
- stdout: "pipe",
415
- stderr: "pipe",
416
- stdin: "pipe",
417
- })
418
- const exit = await proc.exited
419
- if (exit !== 0) {
420
- log.error("Failed to install rubocop")
421
- return
422
- }
423
- bin = path.join(Global.Path.bin, "rubocop" + (process.platform === "win32" ? ".exe" : ""))
424
- log.info(`installed rubocop`, {
425
- bin,
426
- })
427
- }
428
- return {
429
- process: spawn(bin!, ["--lsp"], {
430
- cwd: root,
431
- }),
432
- }
433
- },
434
- }
435
-
436
- export const Ty: Info = {
437
- id: "ty",
438
- extensions: [".py", ".pyi"],
439
- root: NearestRoot([
440
- "pyproject.toml",
441
- "ty.toml",
442
- "setup.py",
443
- "setup.cfg",
444
- "requirements.txt",
445
- "Pipfile",
446
- "pyrightconfig.json",
447
- ]),
448
- async spawn(root) {
449
- if (!Flag.OPENCODE_EXPERIMENTAL_LSP_TY) {
450
- return undefined
451
- }
452
-
453
- let binary = Bun.which("ty")
454
-
455
- const initialization: Record<string, string> = {}
456
-
457
- const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter(
458
- (p): p is string => p !== undefined,
459
- )
460
- for (const venvPath of potentialVenvPaths) {
461
- const isWindows = process.platform === "win32"
462
- const potentialPythonPath = isWindows
463
- ? path.join(venvPath, "Scripts", "python.exe")
464
- : path.join(venvPath, "bin", "python")
465
- if (await Bun.file(potentialPythonPath).exists()) {
466
- initialization["pythonPath"] = potentialPythonPath
467
- break
468
- }
469
- }
470
-
471
- if (!binary) {
472
- for (const venvPath of potentialVenvPaths) {
473
- const isWindows = process.platform === "win32"
474
- const potentialTyPath = isWindows
475
- ? path.join(venvPath, "Scripts", "ty.exe")
476
- : path.join(venvPath, "bin", "ty")
477
- if (await Bun.file(potentialTyPath).exists()) {
478
- binary = potentialTyPath
479
- break
480
- }
481
- }
482
- }
483
-
484
- if (!binary) {
485
- log.error("ty not found, please install ty first")
486
- return
487
- }
488
-
489
- const proc = spawn(binary, ["server"], {
490
- cwd: root,
491
- })
492
-
493
- return {
494
- process: proc,
495
- initialization,
496
- }
497
- },
498
- }
499
-
500
- export const Pyright: Info = {
501
- id: "pyright",
502
- extensions: [".py", ".pyi"],
503
- root: NearestRoot(["pyproject.toml", "setup.py", "setup.cfg", "requirements.txt", "Pipfile", "pyrightconfig.json"]),
504
- async spawn(root) {
505
- let binary = Bun.which("pyright-langserver")
506
- const args = []
507
- if (!binary) {
508
- const js = path.join(Global.Path.bin, "node_modules", "pyright", "dist", "pyright-langserver.js")
509
- if (!(await Bun.file(js).exists())) {
510
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
511
- await Bun.spawn([BunProc.which(), "install", "pyright"], {
512
- cwd: Global.Path.bin,
513
- env: {
514
- ...process.env,
515
- BUN_BE_BUN: "1",
516
- },
517
- }).exited
518
- }
519
- binary = BunProc.which()
520
- args.push(...["run", js])
521
- }
522
- args.push("--stdio")
523
-
524
- const initialization: Record<string, string> = {}
525
-
526
- const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter(
527
- (p): p is string => p !== undefined,
528
- )
529
- for (const venvPath of potentialVenvPaths) {
530
- const isWindows = process.platform === "win32"
531
- const potentialPythonPath = isWindows
532
- ? path.join(venvPath, "Scripts", "python.exe")
533
- : path.join(venvPath, "bin", "python")
534
- if (await Bun.file(potentialPythonPath).exists()) {
535
- initialization["pythonPath"] = potentialPythonPath
536
- break
537
- }
538
- }
539
-
540
- const proc = spawn(binary, args, {
541
- cwd: root,
542
- env: {
543
- ...process.env,
544
- BUN_BE_BUN: "1",
545
- },
546
- })
547
- return {
548
- process: proc,
549
- initialization,
550
- }
551
- },
552
- }
553
-
554
- export const ElixirLS: Info = {
555
- id: "elixir-ls",
556
- extensions: [".ex", ".exs"],
557
- root: NearestRoot(["mix.exs", "mix.lock"]),
558
- async spawn(root) {
559
- let binary = Bun.which("elixir-ls")
560
- if (!binary) {
561
- const elixirLsPath = path.join(Global.Path.bin, "elixir-ls")
562
- binary = path.join(
563
- Global.Path.bin,
564
- "elixir-ls-master",
565
- "release",
566
- process.platform === "win32" ? "language_server.bat" : "language_server.sh",
567
- )
568
-
569
- if (!(await Bun.file(binary).exists())) {
570
- const elixir = Bun.which("elixir")
571
- if (!elixir) {
572
- log.error("elixir is required to run elixir-ls")
573
- return
574
- }
575
-
576
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
577
- log.info("downloading elixir-ls from GitHub releases")
578
-
579
- const response = await fetch("https://github.com/elixir-lsp/elixir-ls/archive/refs/heads/master.zip")
580
- if (!response.ok) return
581
- const zipPath = path.join(Global.Path.bin, "elixir-ls.zip")
582
- await Bun.file(zipPath).write(response)
583
-
584
- const ok = await Archive.extractZip(zipPath, Global.Path.bin)
585
- .then(() => true)
586
- .catch((error) => {
587
- log.error("Failed to extract elixir-ls archive", { error })
588
- return false
589
- })
590
- if (!ok) return
591
-
592
- await fs.rm(zipPath, {
593
- force: true,
594
- recursive: true,
595
- })
596
-
597
- await $`mix deps.get && mix compile && mix elixir_ls.release2 -o release`
598
- .quiet()
599
- .cwd(path.join(Global.Path.bin, "elixir-ls-master"))
600
- .env({ MIX_ENV: "prod", ...process.env })
601
-
602
- log.info(`installed elixir-ls`, {
603
- path: elixirLsPath,
604
- })
605
- }
606
- }
607
-
608
- return {
609
- process: spawn(binary, {
610
- cwd: root,
611
- }),
612
- }
613
- },
614
- }
615
-
616
- export const Zls: Info = {
617
- id: "zls",
618
- extensions: [".zig", ".zon"],
619
- root: NearestRoot(["build.zig"]),
620
- async spawn(root) {
621
- let bin = Bun.which("zls", {
622
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
623
- })
624
-
625
- if (!bin) {
626
- const zig = Bun.which("zig")
627
- if (!zig) {
628
- log.error("Zig is required to use zls. Please install Zig first.")
629
- return
630
- }
631
-
632
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
633
- log.info("downloading zls from GitHub releases")
634
-
635
- const releaseResponse = await fetch("https://api.github.com/repos/zigtools/zls/releases/latest")
636
- if (!releaseResponse.ok) {
637
- log.error("Failed to fetch zls release info")
638
- return
639
- }
640
-
641
- const release = (await releaseResponse.json()) as any
642
-
643
- const platform = process.platform
644
- const arch = process.arch
645
- let assetName = ""
646
-
647
- let zlsArch: string = arch
648
- if (arch === "arm64") zlsArch = "aarch64"
649
- else if (arch === "x64") zlsArch = "x86_64"
650
- else if (arch === "ia32") zlsArch = "x86"
651
-
652
- let zlsPlatform: string = platform
653
- if (platform === "darwin") zlsPlatform = "macos"
654
- else if (platform === "win32") zlsPlatform = "windows"
655
-
656
- const ext = platform === "win32" ? "zip" : "tar.xz"
657
-
658
- assetName = `zls-${zlsArch}-${zlsPlatform}.${ext}`
659
-
660
- const supportedCombos = [
661
- "zls-x86_64-linux.tar.xz",
662
- "zls-x86_64-macos.tar.xz",
663
- "zls-x86_64-windows.zip",
664
- "zls-aarch64-linux.tar.xz",
665
- "zls-aarch64-macos.tar.xz",
666
- "zls-aarch64-windows.zip",
667
- "zls-x86-linux.tar.xz",
668
- "zls-x86-windows.zip",
669
- ]
670
-
671
- if (!supportedCombos.includes(assetName)) {
672
- log.error(`Platform ${platform} and architecture ${arch} is not supported by zls`)
673
- return
674
- }
675
-
676
- const asset = release.assets.find((a: any) => a.name === assetName)
677
- if (!asset) {
678
- log.error(`Could not find asset ${assetName} in latest zls release`)
679
- return
680
- }
681
-
682
- const downloadUrl = asset.browser_download_url
683
- const downloadResponse = await fetch(downloadUrl)
684
- if (!downloadResponse.ok) {
685
- log.error("Failed to download zls")
686
- return
687
- }
688
-
689
- const tempPath = path.join(Global.Path.bin, assetName)
690
- await Bun.file(tempPath).write(downloadResponse)
691
-
692
- if (ext === "zip") {
693
- const ok = await Archive.extractZip(tempPath, Global.Path.bin)
694
- .then(() => true)
695
- .catch((error) => {
696
- log.error("Failed to extract zls archive", { error })
697
- return false
698
- })
699
- if (!ok) return
700
- } else {
701
- await $`tar -xf ${tempPath}`.cwd(Global.Path.bin).quiet().nothrow()
702
- }
703
-
704
- await fs.rm(tempPath, { force: true })
705
-
706
- bin = path.join(Global.Path.bin, "zls" + (platform === "win32" ? ".exe" : ""))
707
-
708
- if (!(await Bun.file(bin).exists())) {
709
- log.error("Failed to extract zls binary")
710
- return
711
- }
712
-
713
- if (platform !== "win32") {
714
- await $`chmod +x ${bin}`.quiet().nothrow()
715
- }
716
-
717
- log.info(`installed zls`, { bin })
718
- }
719
-
720
- return {
721
- process: spawn(bin, {
722
- cwd: root,
723
- }),
724
- }
725
- },
726
- }
727
-
728
- export const CSharp: Info = {
729
- id: "csharp",
730
- root: NearestRoot([".sln", ".csproj", "global.json"]),
731
- extensions: [".cs"],
732
- async spawn(root) {
733
- let bin = Bun.which("csharp-ls", {
734
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
735
- })
736
- if (!bin) {
737
- if (!Bun.which("dotnet")) {
738
- log.error(".NET SDK is required to install csharp-ls")
739
- return
740
- }
741
-
742
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
743
- log.info("installing csharp-ls via dotnet tool")
744
- const proc = Bun.spawn({
745
- cmd: ["dotnet", "tool", "install", "csharp-ls", "--tool-path", Global.Path.bin],
746
- stdout: "pipe",
747
- stderr: "pipe",
748
- stdin: "pipe",
749
- })
750
- const exit = await proc.exited
751
- if (exit !== 0) {
752
- log.error("Failed to install csharp-ls")
753
- return
754
- }
755
-
756
- bin = path.join(Global.Path.bin, "csharp-ls" + (process.platform === "win32" ? ".exe" : ""))
757
- log.info(`installed csharp-ls`, { bin })
758
- }
759
-
760
- return {
761
- process: spawn(bin, {
762
- cwd: root,
763
- }),
764
- }
765
- },
766
- }
767
-
768
- export const FSharp: Info = {
769
- id: "fsharp",
770
- root: NearestRoot([".sln", ".fsproj", "global.json"]),
771
- extensions: [".fs", ".fsi", ".fsx", ".fsscript"],
772
- async spawn(root) {
773
- let bin = Bun.which("fsautocomplete", {
774
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
775
- })
776
- if (!bin) {
777
- if (!Bun.which("dotnet")) {
778
- log.error(".NET SDK is required to install fsautocomplete")
779
- return
780
- }
781
-
782
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
783
- log.info("installing fsautocomplete via dotnet tool")
784
- const proc = Bun.spawn({
785
- cmd: ["dotnet", "tool", "install", "fsautocomplete", "--tool-path", Global.Path.bin],
786
- stdout: "pipe",
787
- stderr: "pipe",
788
- stdin: "pipe",
789
- })
790
- const exit = await proc.exited
791
- if (exit !== 0) {
792
- log.error("Failed to install fsautocomplete")
793
- return
794
- }
795
-
796
- bin = path.join(Global.Path.bin, "fsautocomplete" + (process.platform === "win32" ? ".exe" : ""))
797
- log.info(`installed fsautocomplete`, { bin })
798
- }
799
-
800
- return {
801
- process: spawn(bin, {
802
- cwd: root,
803
- }),
804
- }
805
- },
806
- }
807
-
808
- export const SourceKit: Info = {
809
- id: "sourcekit-lsp",
810
- extensions: [".swift", ".objc", "objcpp"],
811
- root: NearestRoot(["Package.swift", "*.xcodeproj", "*.xcworkspace"]),
812
- async spawn(root) {
813
- // Check if sourcekit-lsp is available in the PATH
814
- // This is installed with the Swift toolchain
815
- const sourcekit = Bun.which("sourcekit-lsp")
816
- if (sourcekit) {
817
- return {
818
- process: spawn(sourcekit, {
819
- cwd: root,
820
- }),
821
- }
822
- }
823
-
824
- // If sourcekit-lsp not found, check if xcrun is available
825
- // This is specific to macOS where sourcekit-lsp is typically installed with Xcode
826
- if (!Bun.which("xcrun")) return
827
-
828
- const lspLoc = await $`xcrun --find sourcekit-lsp`.quiet().nothrow()
829
-
830
- if (lspLoc.exitCode !== 0) return
831
-
832
- const bin = lspLoc.text().trim()
833
-
834
- return {
835
- process: spawn(bin, {
836
- cwd: root,
837
- }),
838
- }
839
- },
840
- }
841
-
842
- export const RustAnalyzer: Info = {
843
- id: "rust",
844
- root: async (root) => {
845
- const crateRoot = await NearestRoot(["Cargo.toml", "Cargo.lock"])(root)
846
- if (crateRoot === undefined) {
847
- return undefined
848
- }
849
- let currentDir = crateRoot
850
-
851
- while (currentDir !== path.dirname(currentDir)) {
852
- // Stop at filesystem root
853
- const cargoTomlPath = path.join(currentDir, "Cargo.toml")
854
- try {
855
- const cargoTomlContent = await Bun.file(cargoTomlPath).text()
856
- if (cargoTomlContent.includes("[workspace]")) {
857
- return currentDir
858
- }
859
- } catch (err) {
860
- // File doesn't exist or can't be read, continue searching up
861
- }
862
-
863
- const parentDir = path.dirname(currentDir)
864
- if (parentDir === currentDir) break // Reached filesystem root
865
- currentDir = parentDir
866
-
867
- // Stop if we've gone above the app root
868
- if (!currentDir.startsWith(Instance.worktree)) break
869
- }
870
-
871
- return crateRoot
872
- },
873
- extensions: [".rs"],
874
- async spawn(root) {
875
- const bin = Bun.which("rust-analyzer")
876
- if (!bin) {
877
- log.info("rust-analyzer not found in path, please install it")
878
- return
879
- }
880
- return {
881
- process: spawn(bin, {
882
- cwd: root,
883
- }),
884
- }
885
- },
886
- }
887
-
888
- export const Clangd: Info = {
889
- id: "clangd",
890
- root: NearestRoot(["compile_commands.json", "compile_flags.txt", ".clangd", "CMakeLists.txt", "Makefile"]),
891
- extensions: [".c", ".cpp", ".cc", ".cxx", ".c++", ".h", ".hpp", ".hh", ".hxx", ".h++"],
892
- async spawn(root) {
893
- const args = ["--background-index", "--clang-tidy"]
894
- const fromPath = Bun.which("clangd")
895
- if (fromPath) {
896
- return {
897
- process: spawn(fromPath, args, {
898
- cwd: root,
899
- }),
900
- }
901
- }
902
-
903
- const ext = process.platform === "win32" ? ".exe" : ""
904
- const direct = path.join(Global.Path.bin, "clangd" + ext)
905
- if (await Bun.file(direct).exists()) {
906
- return {
907
- process: spawn(direct, args, {
908
- cwd: root,
909
- }),
910
- }
911
- }
912
-
913
- const entries = await fs.readdir(Global.Path.bin, { withFileTypes: true }).catch(() => [])
914
- for (const entry of entries) {
915
- if (!entry.isDirectory()) continue
916
- if (!entry.name.startsWith("clangd_")) continue
917
- const candidate = path.join(Global.Path.bin, entry.name, "bin", "clangd" + ext)
918
- if (await Bun.file(candidate).exists()) {
919
- return {
920
- process: spawn(candidate, args, {
921
- cwd: root,
922
- }),
923
- }
924
- }
925
- }
926
-
927
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
928
- log.info("downloading clangd from GitHub releases")
929
-
930
- const releaseResponse = await fetch("https://api.github.com/repos/clangd/clangd/releases/latest")
931
- if (!releaseResponse.ok) {
932
- log.error("Failed to fetch clangd release info")
933
- return
934
- }
935
-
936
- const release: {
937
- tag_name?: string
938
- assets?: { name?: string; browser_download_url?: string }[]
939
- } = await releaseResponse.json()
940
-
941
- const tag = release.tag_name
942
- if (!tag) {
943
- log.error("clangd release did not include a tag name")
944
- return
945
- }
946
- const platform = process.platform
947
- const tokens: Record<string, string> = {
948
- darwin: "mac",
949
- linux: "linux",
950
- win32: "windows",
951
- }
952
- const token = tokens[platform]
953
- if (!token) {
954
- log.error(`Platform ${platform} is not supported by clangd auto-download`)
955
- return
956
- }
957
-
958
- const assets = release.assets ?? []
959
- const valid = (item: { name?: string; browser_download_url?: string }) => {
960
- if (!item.name) return false
961
- if (!item.browser_download_url) return false
962
- if (!item.name.includes(token)) return false
963
- return item.name.includes(tag)
964
- }
965
-
966
- const asset =
967
- assets.find((item) => valid(item) && item.name?.endsWith(".zip")) ??
968
- assets.find((item) => valid(item) && item.name?.endsWith(".tar.xz")) ??
969
- assets.find((item) => valid(item))
970
- if (!asset?.name || !asset.browser_download_url) {
971
- log.error("clangd could not match release asset", { tag, platform })
972
- return
973
- }
974
-
975
- const name = asset.name
976
- const downloadResponse = await fetch(asset.browser_download_url)
977
- if (!downloadResponse.ok) {
978
- log.error("Failed to download clangd")
979
- return
980
- }
981
-
982
- const archive = path.join(Global.Path.bin, name)
983
- const buf = await downloadResponse.arrayBuffer()
984
- if (buf.byteLength === 0) {
985
- log.error("Failed to write clangd archive")
986
- return
987
- }
988
- await Bun.write(archive, buf)
989
-
990
- const zip = name.endsWith(".zip")
991
- const tar = name.endsWith(".tar.xz")
992
- if (!zip && !tar) {
993
- log.error("clangd encountered unsupported asset", { asset: name })
994
- return
995
- }
996
-
997
- if (zip) {
998
- const ok = await Archive.extractZip(archive, Global.Path.bin)
999
- .then(() => true)
1000
- .catch((error) => {
1001
- log.error("Failed to extract clangd archive", { error })
1002
- return false
1003
- })
1004
- if (!ok) return
1005
- }
1006
- if (tar) {
1007
- await $`tar -xf ${archive}`.cwd(Global.Path.bin).quiet().nothrow()
1008
- }
1009
- await fs.rm(archive, { force: true })
1010
-
1011
- const bin = path.join(Global.Path.bin, "clangd_" + tag, "bin", "clangd" + ext)
1012
- if (!(await Bun.file(bin).exists())) {
1013
- log.error("Failed to extract clangd binary")
1014
- return
1015
- }
1016
-
1017
- if (platform !== "win32") {
1018
- await $`chmod +x ${bin}`.quiet().nothrow()
1019
- }
1020
-
1021
- await fs.unlink(path.join(Global.Path.bin, "clangd")).catch(() => {})
1022
- await fs.symlink(bin, path.join(Global.Path.bin, "clangd")).catch(() => {})
1023
-
1024
- log.info(`installed clangd`, { bin })
1025
-
1026
- return {
1027
- process: spawn(bin, args, {
1028
- cwd: root,
1029
- }),
1030
- }
1031
- },
1032
- }
1033
-
1034
- export const Svelte: Info = {
1035
- id: "svelte",
1036
- extensions: [".svelte"],
1037
- root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1038
- async spawn(root) {
1039
- let binary = Bun.which("svelteserver")
1040
- const args: string[] = []
1041
- if (!binary) {
1042
- const js = path.join(Global.Path.bin, "node_modules", "svelte-language-server", "bin", "server.js")
1043
- if (!(await Bun.file(js).exists())) {
1044
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1045
- await Bun.spawn([BunProc.which(), "install", "svelte-language-server"], {
1046
- cwd: Global.Path.bin,
1047
- env: {
1048
- ...process.env,
1049
- BUN_BE_BUN: "1",
1050
- },
1051
- stdout: "pipe",
1052
- stderr: "pipe",
1053
- stdin: "pipe",
1054
- }).exited
1055
- }
1056
- binary = BunProc.which()
1057
- args.push("run", js)
1058
- }
1059
- args.push("--stdio")
1060
- const proc = spawn(binary, args, {
1061
- cwd: root,
1062
- env: {
1063
- ...process.env,
1064
- BUN_BE_BUN: "1",
1065
- },
1066
- })
1067
- return {
1068
- process: proc,
1069
- initialization: {},
1070
- }
1071
- },
1072
- }
1073
-
1074
- export const Astro: Info = {
1075
- id: "astro",
1076
- extensions: [".astro"],
1077
- root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1078
- async spawn(root) {
1079
- const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})
1080
- if (!tsserver) {
1081
- log.info("typescript not found, required for Astro language server")
1082
- return
1083
- }
1084
- const tsdk = path.dirname(tsserver)
1085
-
1086
- let binary = Bun.which("astro-ls")
1087
- const args: string[] = []
1088
- if (!binary) {
1089
- const js = path.join(Global.Path.bin, "node_modules", "@astrojs", "language-server", "bin", "nodeServer.js")
1090
- if (!(await Bun.file(js).exists())) {
1091
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1092
- await Bun.spawn([BunProc.which(), "install", "@astrojs/language-server"], {
1093
- cwd: Global.Path.bin,
1094
- env: {
1095
- ...process.env,
1096
- BUN_BE_BUN: "1",
1097
- },
1098
- stdout: "pipe",
1099
- stderr: "pipe",
1100
- stdin: "pipe",
1101
- }).exited
1102
- }
1103
- binary = BunProc.which()
1104
- args.push("run", js)
1105
- }
1106
- args.push("--stdio")
1107
- const proc = spawn(binary, args, {
1108
- cwd: root,
1109
- env: {
1110
- ...process.env,
1111
- BUN_BE_BUN: "1",
1112
- },
1113
- })
1114
- return {
1115
- process: proc,
1116
- initialization: {
1117
- typescript: {
1118
- tsdk,
1119
- },
1120
- },
1121
- }
1122
- },
1123
- }
1124
-
1125
- export const JDTLS: Info = {
1126
- id: "jdtls",
1127
- root: NearestRoot(["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"]),
1128
- extensions: [".java"],
1129
- async spawn(root) {
1130
- const java = Bun.which("java")
1131
- if (!java) {
1132
- log.error("Java 21 or newer is required to run the JDTLS. Please install it first.")
1133
- return
1134
- }
1135
- const javaMajorVersion = await $`java -version`
1136
- .quiet()
1137
- .nothrow()
1138
- .then(({ stderr }) => {
1139
- const m = /"(\d+)\.\d+\.\d+"/.exec(stderr.toString())
1140
- return !m ? undefined : parseInt(m[1])
1141
- })
1142
- if (javaMajorVersion == null || javaMajorVersion < 21) {
1143
- log.error("JDTLS requires at least Java 21.")
1144
- return
1145
- }
1146
- const distPath = path.join(Global.Path.bin, "jdtls")
1147
- const launcherDir = path.join(distPath, "plugins")
1148
- const installed = await fs.exists(launcherDir)
1149
- if (!installed) {
1150
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1151
- log.info("Downloading JDTLS LSP server.")
1152
- await fs.mkdir(distPath, { recursive: true })
1153
- const releaseURL =
1154
- "https://www.eclipse.org/downloads/download.php?file=/jdtls/snapshots/jdt-language-server-latest.tar.gz"
1155
- const archivePath = path.join(distPath, "release.tar.gz")
1156
- await $`curl -L -o '${archivePath}' '${releaseURL}'`.quiet().nothrow()
1157
- await $`tar -xzf ${archivePath}`.cwd(distPath).quiet().nothrow()
1158
- await fs.rm(archivePath, { force: true })
1159
- }
1160
- const jarFileName = await $`ls org.eclipse.equinox.launcher_*.jar`
1161
- .cwd(launcherDir)
1162
- .quiet()
1163
- .nothrow()
1164
- .then(({ stdout }) => stdout.toString().trim())
1165
- const launcherJar = path.join(launcherDir, jarFileName)
1166
- if (!(await fs.exists(launcherJar))) {
1167
- log.error(`Failed to locate the JDTLS launcher module in the installed directory: ${distPath}.`)
1168
- return
1169
- }
1170
- const configFile = path.join(
1171
- distPath,
1172
- (() => {
1173
- switch (process.platform) {
1174
- case "darwin":
1175
- return "config_mac"
1176
- case "linux":
1177
- return "config_linux"
1178
- case "win32":
1179
- return "config_win"
1180
- default:
1181
- return "config_linux"
1182
- }
1183
- })(),
1184
- )
1185
- const dataDir = await fs.mkdtemp(path.join(os.tmpdir(), "opencode-jdtls-data"))
1186
- return {
1187
- process: spawn(
1188
- java,
1189
- [
1190
- "-jar",
1191
- launcherJar,
1192
- "-configuration",
1193
- configFile,
1194
- "-data",
1195
- dataDir,
1196
- "-Declipse.application=org.eclipse.jdt.ls.core.id1",
1197
- "-Dosgi.bundles.defaultStartLevel=4",
1198
- "-Declipse.product=org.eclipse.jdt.ls.core.product",
1199
- "-Dlog.level=ALL",
1200
- "--add-modules=ALL-SYSTEM",
1201
- "--add-opens java.base/java.util=ALL-UNNAMED",
1202
- "--add-opens java.base/java.lang=ALL-UNNAMED",
1203
- ],
1204
- {
1205
- cwd: root,
1206
- },
1207
- ),
1208
- }
1209
- },
1210
- }
1211
-
1212
- export const KotlinLS: Info = {
1213
- id: "kotlin-ls",
1214
- extensions: [".kt", ".kts"],
1215
- root: async (file) => {
1216
- // 1) Nearest Gradle root (multi-project or included build)
1217
- const settingsRoot = await NearestRoot(["settings.gradle.kts", "settings.gradle"])(file)
1218
- if (settingsRoot) return settingsRoot
1219
- // 2) Gradle wrapper (strong root signal)
1220
- const wrapperRoot = await NearestRoot(["gradlew", "gradlew.bat"])(file)
1221
- if (wrapperRoot) return wrapperRoot
1222
- // 3) Single-project or module-level build
1223
- const buildRoot = await NearestRoot(["build.gradle.kts", "build.gradle"])(file)
1224
- if (buildRoot) return buildRoot
1225
- // 4) Maven fallback
1226
- return NearestRoot(["pom.xml"])(file)
1227
- },
1228
- async spawn(root) {
1229
- const distPath = path.join(Global.Path.bin, "kotlin-ls")
1230
- const launcherScript =
1231
- process.platform === "win32" ? path.join(distPath, "kotlin-lsp.cmd") : path.join(distPath, "kotlin-lsp.sh")
1232
- const installed = await Bun.file(launcherScript).exists()
1233
- if (!installed) {
1234
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1235
- log.info("Downloading Kotlin Language Server from GitHub.")
1236
-
1237
- const releaseResponse = await fetch("https://api.github.com/repos/Kotlin/kotlin-lsp/releases/latest")
1238
- if (!releaseResponse.ok) {
1239
- log.error("Failed to fetch kotlin-lsp release info")
1240
- return
1241
- }
1242
-
1243
- const release = await releaseResponse.json()
1244
- const version = release.name?.replace(/^v/, "")
1245
-
1246
- if (!version) {
1247
- log.error("Could not determine Kotlin LSP version from release")
1248
- return
1249
- }
1250
-
1251
- const platform = process.platform
1252
- const arch = process.arch
1253
-
1254
- let kotlinArch: string = arch
1255
- if (arch === "arm64") kotlinArch = "aarch64"
1256
- else if (arch === "x64") kotlinArch = "x64"
1257
-
1258
- let kotlinPlatform: string = platform
1259
- if (platform === "darwin") kotlinPlatform = "mac"
1260
- else if (platform === "linux") kotlinPlatform = "linux"
1261
- else if (platform === "win32") kotlinPlatform = "win"
1262
-
1263
- const supportedCombos = ["mac-x64", "mac-aarch64", "linux-x64", "linux-aarch64", "win-x64", "win-aarch64"]
1264
-
1265
- const combo = `${kotlinPlatform}-${kotlinArch}`
1266
-
1267
- if (!supportedCombos.includes(combo)) {
1268
- log.error(`Platform ${platform}/${arch} is not supported by Kotlin LSP`)
1269
- return
1270
- }
1271
-
1272
- const assetName = `kotlin-lsp-${version}-${kotlinPlatform}-${kotlinArch}.zip`
1273
- const releaseURL = `https://download-cdn.jetbrains.com/kotlin-lsp/${version}/${assetName}`
1274
-
1275
- await fs.mkdir(distPath, { recursive: true })
1276
- const archivePath = path.join(distPath, "kotlin-ls.zip")
1277
- await $`curl -L -o '${archivePath}' '${releaseURL}'`.quiet().nothrow()
1278
- const ok = await Archive.extractZip(archivePath, distPath)
1279
- .then(() => true)
1280
- .catch((error) => {
1281
- log.error("Failed to extract Kotlin LS archive", { error })
1282
- return false
1283
- })
1284
- if (!ok) return
1285
- await fs.rm(archivePath, { force: true })
1286
- if (process.platform !== "win32") {
1287
- await $`chmod +x ${launcherScript}`.quiet().nothrow()
1288
- }
1289
- log.info("Installed Kotlin Language Server", { path: launcherScript })
1290
- }
1291
- if (!(await Bun.file(launcherScript).exists())) {
1292
- log.error(`Failed to locate the Kotlin LS launcher script in the installed directory: ${distPath}.`)
1293
- return
1294
- }
1295
- return {
1296
- process: spawn(launcherScript, ["--stdio"], {
1297
- cwd: root,
1298
- }),
1299
- }
1300
- },
1301
- }
1302
-
1303
- export const YamlLS: Info = {
1304
- id: "yaml-ls",
1305
- extensions: [".yaml", ".yml"],
1306
- root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
1307
- async spawn(root) {
1308
- let binary = Bun.which("yaml-language-server")
1309
- const args: string[] = []
1310
- if (!binary) {
1311
- const js = path.join(
1312
- Global.Path.bin,
1313
- "node_modules",
1314
- "yaml-language-server",
1315
- "out",
1316
- "server",
1317
- "src",
1318
- "server.js",
1319
- )
1320
- const exists = await Bun.file(js).exists()
1321
- if (!exists) {
1322
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1323
- await Bun.spawn([BunProc.which(), "install", "yaml-language-server"], {
1324
- cwd: Global.Path.bin,
1325
- env: {
1326
- ...process.env,
1327
- BUN_BE_BUN: "1",
1328
- },
1329
- stdout: "pipe",
1330
- stderr: "pipe",
1331
- stdin: "pipe",
1332
- }).exited
1333
- }
1334
- binary = BunProc.which()
1335
- args.push("run", js)
1336
- }
1337
- args.push("--stdio")
1338
- const proc = spawn(binary, args, {
1339
- cwd: root,
1340
- env: {
1341
- ...process.env,
1342
- BUN_BE_BUN: "1",
1343
- },
1344
- })
1345
- return {
1346
- process: proc,
1347
- }
1348
- },
1349
- }
1350
-
1351
- export const LuaLS: Info = {
1352
- id: "lua-ls",
1353
- root: NearestRoot([
1354
- ".luarc.json",
1355
- ".luarc.jsonc",
1356
- ".luacheckrc",
1357
- ".stylua.toml",
1358
- "stylua.toml",
1359
- "selene.toml",
1360
- "selene.yml",
1361
- ]),
1362
- extensions: [".lua"],
1363
- async spawn(root) {
1364
- let bin = Bun.which("lua-language-server", {
1365
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1366
- })
1367
-
1368
- if (!bin) {
1369
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1370
- log.info("downloading lua-language-server from GitHub releases")
1371
-
1372
- const releaseResponse = await fetch("https://api.github.com/repos/LuaLS/lua-language-server/releases/latest")
1373
- if (!releaseResponse.ok) {
1374
- log.error("Failed to fetch lua-language-server release info")
1375
- return
1376
- }
1377
-
1378
- const release = await releaseResponse.json()
1379
-
1380
- const platform = process.platform
1381
- const arch = process.arch
1382
- let assetName = ""
1383
-
1384
- let lualsArch: string = arch
1385
- if (arch === "arm64") lualsArch = "arm64"
1386
- else if (arch === "x64") lualsArch = "x64"
1387
- else if (arch === "ia32") lualsArch = "ia32"
1388
-
1389
- let lualsPlatform: string = platform
1390
- if (platform === "darwin") lualsPlatform = "darwin"
1391
- else if (platform === "linux") lualsPlatform = "linux"
1392
- else if (platform === "win32") lualsPlatform = "win32"
1393
-
1394
- const ext = platform === "win32" ? "zip" : "tar.gz"
1395
-
1396
- assetName = `lua-language-server-${release.tag_name}-${lualsPlatform}-${lualsArch}.${ext}`
1397
-
1398
- const supportedCombos = [
1399
- "darwin-arm64.tar.gz",
1400
- "darwin-x64.tar.gz",
1401
- "linux-x64.tar.gz",
1402
- "linux-arm64.tar.gz",
1403
- "win32-x64.zip",
1404
- "win32-ia32.zip",
1405
- ]
1406
-
1407
- const assetSuffix = `${lualsPlatform}-${lualsArch}.${ext}`
1408
- if (!supportedCombos.includes(assetSuffix)) {
1409
- log.error(`Platform ${platform} and architecture ${arch} is not supported by lua-language-server`)
1410
- return
1411
- }
1412
-
1413
- const asset = release.assets.find((a: any) => a.name === assetName)
1414
- if (!asset) {
1415
- log.error(`Could not find asset ${assetName} in latest lua-language-server release`)
1416
- return
1417
- }
1418
-
1419
- const downloadUrl = asset.browser_download_url
1420
- const downloadResponse = await fetch(downloadUrl)
1421
- if (!downloadResponse.ok) {
1422
- log.error("Failed to download lua-language-server")
1423
- return
1424
- }
1425
-
1426
- const tempPath = path.join(Global.Path.bin, assetName)
1427
- await Bun.file(tempPath).write(downloadResponse)
1428
-
1429
- // Unlike zls which is a single self-contained binary,
1430
- // lua-language-server needs supporting files (meta/, locale/, etc.)
1431
- // Extract entire archive to dedicated directory to preserve all files
1432
- const installDir = path.join(Global.Path.bin, `lua-language-server-${lualsArch}-${lualsPlatform}`)
1433
-
1434
- // Remove old installation if exists
1435
- const stats = await fs.stat(installDir).catch(() => undefined)
1436
- if (stats) {
1437
- await fs.rm(installDir, { force: true, recursive: true })
1438
- }
1439
-
1440
- await fs.mkdir(installDir, { recursive: true })
1441
-
1442
- if (ext === "zip") {
1443
- const ok = await Archive.extractZip(tempPath, installDir)
1444
- .then(() => true)
1445
- .catch((error) => {
1446
- log.error("Failed to extract lua-language-server archive", { error })
1447
- return false
1448
- })
1449
- if (!ok) return
1450
- } else {
1451
- const ok = await $`tar -xzf ${tempPath} -C ${installDir}`
1452
- .quiet()
1453
- .then(() => true)
1454
- .catch((error) => {
1455
- log.error("Failed to extract lua-language-server archive", { error })
1456
- return false
1457
- })
1458
- if (!ok) return
1459
- }
1460
-
1461
- await fs.rm(tempPath, { force: true })
1462
-
1463
- // Binary is located in bin/ subdirectory within the extracted archive
1464
- bin = path.join(installDir, "bin", "lua-language-server" + (platform === "win32" ? ".exe" : ""))
1465
-
1466
- if (!(await Bun.file(bin).exists())) {
1467
- log.error("Failed to extract lua-language-server binary")
1468
- return
1469
- }
1470
-
1471
- if (platform !== "win32") {
1472
- const ok = await $`chmod +x ${bin}`.quiet().catch((error) => {
1473
- log.error("Failed to set executable permission for lua-language-server binary", {
1474
- error,
1475
- })
1476
- })
1477
- if (!ok) return
1478
- }
1479
-
1480
- log.info(`installed lua-language-server`, { bin })
1481
- }
1482
-
1483
- return {
1484
- process: spawn(bin, {
1485
- cwd: root,
1486
- }),
1487
- }
1488
- },
1489
- }
1490
-
1491
- export const PHPIntelephense: Info = {
1492
- id: "php intelephense",
1493
- extensions: [".php"],
1494
- root: NearestRoot(["composer.json", "composer.lock", ".php-version"]),
1495
- async spawn(root) {
1496
- let binary = Bun.which("intelephense")
1497
- const args: string[] = []
1498
- if (!binary) {
1499
- const js = path.join(Global.Path.bin, "node_modules", "intelephense", "lib", "intelephense.js")
1500
- if (!(await Bun.file(js).exists())) {
1501
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1502
- await Bun.spawn([BunProc.which(), "install", "intelephense"], {
1503
- cwd: Global.Path.bin,
1504
- env: {
1505
- ...process.env,
1506
- BUN_BE_BUN: "1",
1507
- },
1508
- stdout: "pipe",
1509
- stderr: "pipe",
1510
- stdin: "pipe",
1511
- }).exited
1512
- }
1513
- binary = BunProc.which()
1514
- args.push("run", js)
1515
- }
1516
- args.push("--stdio")
1517
- const proc = spawn(binary, args, {
1518
- cwd: root,
1519
- env: {
1520
- ...process.env,
1521
- BUN_BE_BUN: "1",
1522
- },
1523
- })
1524
- return {
1525
- process: proc,
1526
- initialization: {},
1527
- }
1528
- },
1529
- }
1530
-
1531
- export const Prisma: Info = {
1532
- id: "prisma",
1533
- extensions: [".prisma"],
1534
- root: NearestRoot(["schema.prisma", "prisma/schema.prisma", "prisma"], ["package.json"]),
1535
- async spawn(root) {
1536
- const prisma = Bun.which("prisma")
1537
- if (!prisma) {
1538
- log.info("prisma not found, please install prisma")
1539
- return
1540
- }
1541
- return {
1542
- process: spawn(prisma, ["language-server"], {
1543
- cwd: root,
1544
- }),
1545
- }
1546
- },
1547
- }
1548
-
1549
- export const Dart: Info = {
1550
- id: "dart",
1551
- extensions: [".dart"],
1552
- root: NearestRoot(["pubspec.yaml", "analysis_options.yaml"]),
1553
- async spawn(root) {
1554
- const dart = Bun.which("dart")
1555
- if (!dart) {
1556
- log.info("dart not found, please install dart first")
1557
- return
1558
- }
1559
- return {
1560
- process: spawn(dart, ["language-server", "--lsp"], {
1561
- cwd: root,
1562
- }),
1563
- }
1564
- },
1565
- }
1566
-
1567
- export const Ocaml: Info = {
1568
- id: "ocaml-lsp",
1569
- extensions: [".ml", ".mli"],
1570
- root: NearestRoot(["dune-project", "dune-workspace", ".merlin", "opam"]),
1571
- async spawn(root) {
1572
- const bin = Bun.which("ocamllsp")
1573
- if (!bin) {
1574
- log.info("ocamllsp not found, please install ocaml-lsp-server")
1575
- return
1576
- }
1577
- return {
1578
- process: spawn(bin, {
1579
- cwd: root,
1580
- }),
1581
- }
1582
- },
1583
- }
1584
- export const BashLS: Info = {
1585
- id: "bash",
1586
- extensions: [".sh", ".bash", ".zsh", ".ksh"],
1587
- root: async () => Instance.directory,
1588
- async spawn(root) {
1589
- let binary = Bun.which("bash-language-server")
1590
- const args: string[] = []
1591
- if (!binary) {
1592
- const js = path.join(Global.Path.bin, "node_modules", "bash-language-server", "out", "cli.js")
1593
- if (!(await Bun.file(js).exists())) {
1594
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1595
- await Bun.spawn([BunProc.which(), "install", "bash-language-server"], {
1596
- cwd: Global.Path.bin,
1597
- env: {
1598
- ...process.env,
1599
- BUN_BE_BUN: "1",
1600
- },
1601
- stdout: "pipe",
1602
- stderr: "pipe",
1603
- stdin: "pipe",
1604
- }).exited
1605
- }
1606
- binary = BunProc.which()
1607
- args.push("run", js)
1608
- }
1609
- args.push("start")
1610
- const proc = spawn(binary, args, {
1611
- cwd: root,
1612
- env: {
1613
- ...process.env,
1614
- BUN_BE_BUN: "1",
1615
- },
1616
- })
1617
- return {
1618
- process: proc,
1619
- }
1620
- },
1621
- }
1622
-
1623
- export const TerraformLS: Info = {
1624
- id: "terraform",
1625
- extensions: [".tf", ".tfvars"],
1626
- root: NearestRoot([".terraform.lock.hcl", "terraform.tfstate", "*.tf"]),
1627
- async spawn(root) {
1628
- let bin = Bun.which("terraform-ls", {
1629
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1630
- })
1631
-
1632
- if (!bin) {
1633
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1634
- log.info("downloading terraform-ls from GitHub releases")
1635
-
1636
- const releaseResponse = await fetch("https://api.github.com/repos/hashicorp/terraform-ls/releases/latest")
1637
- if (!releaseResponse.ok) {
1638
- log.error("Failed to fetch terraform-ls release info")
1639
- return
1640
- }
1641
-
1642
- const release = (await releaseResponse.json()) as {
1643
- tag_name?: string
1644
- assets?: { name?: string; browser_download_url?: string }[]
1645
- }
1646
- const version = release.tag_name?.replace("v", "")
1647
- if (!version) {
1648
- log.error("terraform-ls release did not include a version tag")
1649
- return
1650
- }
1651
-
1652
- const platform = process.platform
1653
- const arch = process.arch
1654
-
1655
- const tfArch = arch === "arm64" ? "arm64" : "amd64"
1656
- const tfPlatform = platform === "win32" ? "windows" : platform
1657
-
1658
- const assetName = `terraform-ls_${version}_${tfPlatform}_${tfArch}.zip`
1659
-
1660
- const assets = release.assets ?? []
1661
- const asset = assets.find((a) => a.name === assetName)
1662
- if (!asset?.browser_download_url) {
1663
- log.error(`Could not find asset ${assetName} in terraform-ls release`)
1664
- return
1665
- }
1666
-
1667
- const downloadResponse = await fetch(asset.browser_download_url)
1668
- if (!downloadResponse.ok) {
1669
- log.error("Failed to download terraform-ls")
1670
- return
1671
- }
1672
-
1673
- const tempPath = path.join(Global.Path.bin, assetName)
1674
- await Bun.file(tempPath).write(downloadResponse)
1675
-
1676
- const ok = await Archive.extractZip(tempPath, Global.Path.bin)
1677
- .then(() => true)
1678
- .catch((error) => {
1679
- log.error("Failed to extract terraform-ls archive", { error })
1680
- return false
1681
- })
1682
- if (!ok) return
1683
- await fs.rm(tempPath, { force: true })
1684
-
1685
- bin = path.join(Global.Path.bin, "terraform-ls" + (platform === "win32" ? ".exe" : ""))
1686
-
1687
- if (!(await Bun.file(bin).exists())) {
1688
- log.error("Failed to extract terraform-ls binary")
1689
- return
1690
- }
1691
-
1692
- if (platform !== "win32") {
1693
- await $`chmod +x ${bin}`.quiet().nothrow()
1694
- }
1695
-
1696
- log.info(`installed terraform-ls`, { bin })
1697
- }
1698
-
1699
- return {
1700
- process: spawn(bin, ["serve"], {
1701
- cwd: root,
1702
- }),
1703
- initialization: {
1704
- experimentalFeatures: {
1705
- prefillRequiredFields: true,
1706
- validateOnSave: true,
1707
- },
1708
- },
1709
- }
1710
- },
1711
- }
1712
-
1713
- export const TexLab: Info = {
1714
- id: "texlab",
1715
- extensions: [".tex", ".bib"],
1716
- root: NearestRoot([".latexmkrc", "latexmkrc", ".texlabroot", "texlabroot"]),
1717
- async spawn(root) {
1718
- let bin = Bun.which("texlab", {
1719
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1720
- })
1721
-
1722
- if (!bin) {
1723
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1724
- log.info("downloading texlab from GitHub releases")
1725
-
1726
- const response = await fetch("https://api.github.com/repos/latex-lsp/texlab/releases/latest")
1727
- if (!response.ok) {
1728
- log.error("Failed to fetch texlab release info")
1729
- return
1730
- }
1731
-
1732
- const release = (await response.json()) as {
1733
- tag_name?: string
1734
- assets?: { name?: string; browser_download_url?: string }[]
1735
- }
1736
- const version = release.tag_name?.replace("v", "")
1737
- if (!version) {
1738
- log.error("texlab release did not include a version tag")
1739
- return
1740
- }
1741
-
1742
- const platform = process.platform
1743
- const arch = process.arch
1744
-
1745
- const texArch = arch === "arm64" ? "aarch64" : "x86_64"
1746
- const texPlatform = platform === "darwin" ? "macos" : platform === "win32" ? "windows" : "linux"
1747
- const ext = platform === "win32" ? "zip" : "tar.gz"
1748
- const assetName = `texlab-${texArch}-${texPlatform}.${ext}`
1749
-
1750
- const assets = release.assets ?? []
1751
- const asset = assets.find((a) => a.name === assetName)
1752
- if (!asset?.browser_download_url) {
1753
- log.error(`Could not find asset ${assetName} in texlab release`)
1754
- return
1755
- }
1756
-
1757
- const downloadResponse = await fetch(asset.browser_download_url)
1758
- if (!downloadResponse.ok) {
1759
- log.error("Failed to download texlab")
1760
- return
1761
- }
1762
-
1763
- const tempPath = path.join(Global.Path.bin, assetName)
1764
- await Bun.file(tempPath).write(downloadResponse)
1765
-
1766
- if (ext === "zip") {
1767
- const ok = await Archive.extractZip(tempPath, Global.Path.bin)
1768
- .then(() => true)
1769
- .catch((error) => {
1770
- log.error("Failed to extract texlab archive", { error })
1771
- return false
1772
- })
1773
- if (!ok) return
1774
- }
1775
- if (ext === "tar.gz") {
1776
- await $`tar -xzf ${tempPath}`.cwd(Global.Path.bin).quiet().nothrow()
1777
- }
1778
-
1779
- await fs.rm(tempPath, { force: true })
1780
-
1781
- bin = path.join(Global.Path.bin, "texlab" + (platform === "win32" ? ".exe" : ""))
1782
-
1783
- if (!(await Bun.file(bin).exists())) {
1784
- log.error("Failed to extract texlab binary")
1785
- return
1786
- }
1787
-
1788
- if (platform !== "win32") {
1789
- await $`chmod +x ${bin}`.quiet().nothrow()
1790
- }
1791
-
1792
- log.info("installed texlab", { bin })
1793
- }
1794
-
1795
- return {
1796
- process: spawn(bin, {
1797
- cwd: root,
1798
- }),
1799
- }
1800
- },
1801
- }
1802
-
1803
- export const DockerfileLS: Info = {
1804
- id: "dockerfile",
1805
- extensions: [".dockerfile", "Dockerfile"],
1806
- root: async () => Instance.directory,
1807
- async spawn(root) {
1808
- let binary = Bun.which("docker-langserver")
1809
- const args: string[] = []
1810
- if (!binary) {
1811
- const js = path.join(Global.Path.bin, "node_modules", "dockerfile-language-server-nodejs", "lib", "server.js")
1812
- if (!(await Bun.file(js).exists())) {
1813
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1814
- await Bun.spawn([BunProc.which(), "install", "dockerfile-language-server-nodejs"], {
1815
- cwd: Global.Path.bin,
1816
- env: {
1817
- ...process.env,
1818
- BUN_BE_BUN: "1",
1819
- },
1820
- stdout: "pipe",
1821
- stderr: "pipe",
1822
- stdin: "pipe",
1823
- }).exited
1824
- }
1825
- binary = BunProc.which()
1826
- args.push("run", js)
1827
- }
1828
- args.push("--stdio")
1829
- const proc = spawn(binary, args, {
1830
- cwd: root,
1831
- env: {
1832
- ...process.env,
1833
- BUN_BE_BUN: "1",
1834
- },
1835
- })
1836
- return {
1837
- process: proc,
1838
- }
1839
- },
1840
- }
1841
-
1842
- export const Gleam: Info = {
1843
- id: "gleam",
1844
- extensions: [".gleam"],
1845
- root: NearestRoot(["gleam.toml"]),
1846
- async spawn(root) {
1847
- const gleam = Bun.which("gleam")
1848
- if (!gleam) {
1849
- log.info("gleam not found, please install gleam first")
1850
- return
1851
- }
1852
- return {
1853
- process: spawn(gleam, ["lsp"], {
1854
- cwd: root,
1855
- }),
1856
- }
1857
- },
1858
- }
1859
-
1860
- export const Clojure: Info = {
1861
- id: "clojure-lsp",
1862
- extensions: [".clj", ".cljs", ".cljc", ".edn"],
1863
- root: NearestRoot(["deps.edn", "project.clj", "shadow-cljs.edn", "bb.edn", "build.boot"]),
1864
- async spawn(root) {
1865
- let bin = Bun.which("clojure-lsp")
1866
- if (!bin && process.platform === "win32") {
1867
- bin = Bun.which("clojure-lsp.exe")
1868
- }
1869
- if (!bin) {
1870
- log.info("clojure-lsp not found, please install clojure-lsp first")
1871
- return
1872
- }
1873
- return {
1874
- process: spawn(bin, ["listen"], {
1875
- cwd: root,
1876
- }),
1877
- }
1878
- },
1879
- }
1880
-
1881
- export const Nixd: Info = {
1882
- id: "nixd",
1883
- extensions: [".nix"],
1884
- root: async (file) => {
1885
- // First, look for flake.nix - the most reliable Nix project root indicator
1886
- const flakeRoot = await NearestRoot(["flake.nix"])(file)
1887
- if (flakeRoot && flakeRoot !== Instance.directory) return flakeRoot
1888
-
1889
- // If no flake.nix, fall back to git repository root
1890
- if (Instance.worktree && Instance.worktree !== Instance.directory) return Instance.worktree
1891
-
1892
- // Finally, use the instance directory as fallback
1893
- return Instance.directory
1894
- },
1895
- async spawn(root) {
1896
- const nixd = Bun.which("nixd")
1897
- if (!nixd) {
1898
- log.info("nixd not found, please install nixd first")
1899
- return
1900
- }
1901
- return {
1902
- process: spawn(nixd, [], {
1903
- cwd: root,
1904
- env: {
1905
- ...process.env,
1906
- },
1907
- }),
1908
- }
1909
- },
1910
- }
1911
-
1912
- export const Tinymist: Info = {
1913
- id: "tinymist",
1914
- extensions: [".typ", ".typc"],
1915
- root: NearestRoot(["typst.toml"]),
1916
- async spawn(root) {
1917
- let bin = Bun.which("tinymist", {
1918
- PATH: process.env["PATH"] + path.delimiter + Global.Path.bin,
1919
- })
1920
-
1921
- if (!bin) {
1922
- if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
1923
- log.info("downloading tinymist from GitHub releases")
1924
-
1925
- const response = await fetch("https://api.github.com/repos/Myriad-Dreamin/tinymist/releases/latest")
1926
- if (!response.ok) {
1927
- log.error("Failed to fetch tinymist release info")
1928
- return
1929
- }
1930
-
1931
- const release = (await response.json()) as {
1932
- tag_name?: string
1933
- assets?: { name?: string; browser_download_url?: string }[]
1934
- }
1935
-
1936
- const platform = process.platform
1937
- const arch = process.arch
1938
-
1939
- const tinymistArch = arch === "arm64" ? "aarch64" : "x86_64"
1940
- let tinymistPlatform: string
1941
- let ext: string
1942
-
1943
- if (platform === "darwin") {
1944
- tinymistPlatform = "apple-darwin"
1945
- ext = "tar.gz"
1946
- } else if (platform === "win32") {
1947
- tinymistPlatform = "pc-windows-msvc"
1948
- ext = "zip"
1949
- } else {
1950
- tinymistPlatform = "unknown-linux-gnu"
1951
- ext = "tar.gz"
1952
- }
1953
-
1954
- const assetName = `tinymist-${tinymistArch}-${tinymistPlatform}.${ext}`
1955
-
1956
- const assets = release.assets ?? []
1957
- const asset = assets.find((a) => a.name === assetName)
1958
- if (!asset?.browser_download_url) {
1959
- log.error(`Could not find asset ${assetName} in tinymist release`)
1960
- return
1961
- }
1962
-
1963
- const downloadResponse = await fetch(asset.browser_download_url)
1964
- if (!downloadResponse.ok) {
1965
- log.error("Failed to download tinymist")
1966
- return
1967
- }
1968
-
1969
- const tempPath = path.join(Global.Path.bin, assetName)
1970
- await Bun.file(tempPath).write(downloadResponse)
1971
-
1972
- if (ext === "zip") {
1973
- const ok = await Archive.extractZip(tempPath, Global.Path.bin)
1974
- .then(() => true)
1975
- .catch((error) => {
1976
- log.error("Failed to extract tinymist archive", { error })
1977
- return false
1978
- })
1979
- if (!ok) return
1980
- } else {
1981
- await $`tar -xzf ${tempPath} --strip-components=1`.cwd(Global.Path.bin).quiet().nothrow()
1982
- }
1983
-
1984
- await fs.rm(tempPath, { force: true })
1985
-
1986
- bin = path.join(Global.Path.bin, "tinymist" + (platform === "win32" ? ".exe" : ""))
1987
-
1988
- if (!(await Bun.file(bin).exists())) {
1989
- log.error("Failed to extract tinymist binary")
1990
- return
1991
- }
1992
-
1993
- if (platform !== "win32") {
1994
- await $`chmod +x ${bin}`.quiet().nothrow()
1995
- }
1996
-
1997
- log.info("installed tinymist", { bin })
1998
- }
1999
-
2000
- return {
2001
- process: spawn(bin, { cwd: root }),
2002
- }
2003
- },
2004
- }
2005
-
2006
- export const HLS: Info = {
2007
- id: "haskell-language-server",
2008
- extensions: [".hs", ".lhs"],
2009
- root: NearestRoot(["stack.yaml", "cabal.project", "hie.yaml", "*.cabal"]),
2010
- async spawn(root) {
2011
- const bin = Bun.which("haskell-language-server-wrapper")
2012
- if (!bin) {
2013
- log.info("haskell-language-server-wrapper not found, please install haskell-language-server")
2014
- return
2015
- }
2016
- return {
2017
- process: spawn(bin, ["--lsp"], {
2018
- cwd: root,
2019
- }),
2020
- }
2021
- },
2022
- }
2023
- }