Skip to content

Commit 1414642

Browse files
authored
lsp: add oxlint server (anomalyco#5570)
1 parent 26d0280 commit 1414642

File tree

2 files changed

+100
-28
lines changed

2 files changed

+100
-28
lines changed

packages/opencode/src/lsp/server.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from "os"
44
import { Global } from "../global"
55
import { Log } from "../util/log"
66
import { BunProc } from "../bun"
7-
import { $ } from "bun"
7+
import { $, readableStreamToText } from "bun"
88
import fs from "fs/promises"
99
import { Filesystem } from "../util/filesystem"
1010
import { Instance } from "../project/instance"
@@ -216,6 +216,77 @@ export namespace LSPServer {
216216
},
217217
}
218218

219+
export const Oxlint: Info = {
220+
id: "oxlint",
221+
root: NearestRoot([
222+
".oxlintrc.json",
223+
"package-lock.json",
224+
"bun.lockb",
225+
"bun.lock",
226+
"pnpm-lock.yaml",
227+
"yarn.lock",
228+
"package.json",
229+
]),
230+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".astro", ".svelte"],
231+
async spawn(root) {
232+
const ext = process.platform === "win32" ? ".cmd" : ""
233+
234+
const serverTarget = path.join("node_modules", ".bin", "oxc_language_server" + ext)
235+
const lintTarget = path.join("node_modules", ".bin", "oxlint" + ext)
236+
237+
const resolveBin = async (target: string) => {
238+
const localBin = path.join(root, target)
239+
if (await Bun.file(localBin).exists()) return localBin
240+
241+
const candidates = Filesystem.up({
242+
targets: [target],
243+
start: root,
244+
stop: Instance.worktree,
245+
})
246+
const first = await candidates.next()
247+
await candidates.return()
248+
if (first.value) return first.value
249+
250+
return undefined
251+
}
252+
253+
let lintBin = await resolveBin(lintTarget)
254+
if (!lintBin) {
255+
const found = Bun.which("oxlint")
256+
if (found) lintBin = found
257+
}
258+
259+
if (lintBin) {
260+
const proc = Bun.spawn([lintBin, "--help"], { stdout: "pipe" })
261+
await proc.exited
262+
const help = await readableStreamToText(proc.stdout)
263+
if (help.includes("--lsp")) {
264+
return {
265+
process: spawn(lintBin, ["--lsp"], {
266+
cwd: root,
267+
}),
268+
}
269+
}
270+
}
271+
272+
let serverBin = await resolveBin(serverTarget)
273+
if (!serverBin) {
274+
const found = Bun.which("oxc_language_server")
275+
if (found) serverBin = found
276+
}
277+
if (serverBin) {
278+
return {
279+
process: spawn(serverBin, [], {
280+
cwd: root,
281+
}),
282+
}
283+
}
284+
285+
log.info("oxlint not found, please install oxlint")
286+
return
287+
},
288+
}
289+
219290
export const Biome: Info = {
220291
id: "biome",
221292
root: NearestRoot([

packages/web/src/content/docs/lsp.mdx

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,34 @@ OpenCode integrates with your Language Server Protocol (LSP) to help the LLM int
1111

1212
OpenCode comes with several built-in LSP servers for popular languages:
1313

14-
| LSP Server | Extensions | Requirements |
15-
| ------------------ | ---------------------------------------------------- | ------------------------------------------------------------ |
16-
| astro | .astro | Auto-installs for Astro projects |
17-
| bash | .sh, .bash, .zsh, .ksh | Auto-installs bash-language-server |
18-
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
19-
| csharp | .cs | `.NET SDK` installed |
20-
| dart | .dart | `dart` command available |
21-
| deno | .ts, .tsx, .js, .jsx, .mjs | `deno` command available (auto-detects deno.json/deno.jsonc) |
22-
| elixir-ls | .ex, .exs | `elixir` command available |
23-
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | `eslint` dependency in project |
24-
| fsharp | .fs, .fsi, .fsx, .fsscript | `.NET SDK` installed |
25-
| gleam | .gleam | `gleam` command available |
26-
| gopls | .go | `go` command available |
27-
| jdtls | .java | `Java SDK (version 21+)` installed |
28-
| lua-ls | .lua | Auto-installs for Lua projects |
29-
| ocaml-lsp | .ml, .mli | `ocamllsp` command available |
30-
| php intelephense | .php | Auto-installs for PHP projects |
31-
| pyright | .py, .pyi | `pyright` dependency installed |
32-
| ruby-lsp (rubocop) | .rb, .rake, .gemspec, .ru | `ruby` and `gem` commands available |
33-
| rust | .rs | `rust-analyzer` command available |
34-
| sourcekit-lsp | .swift, .objc, .objcpp | `swift` installed (`xcode` on macOS) |
35-
| svelte | .svelte | Auto-installs for Svelte projects |
36-
| terraform | .tf, .tfvars | Auto-installs from GitHub releases |
37-
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | `typescript` dependency in project |
38-
| vue | .vue | Auto-installs for Vue projects |
39-
| yaml-ls | .yaml, .yml | Auto-installs Red Hat yaml-language-server |
40-
| zls | .zig, .zon | `zig` command available |
14+
| LSP Server | Extensions | Requirements |
15+
| ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------ |
16+
| astro | .astro | Auto-installs for Astro projects |
17+
| bash | .sh, .bash, .zsh, .ksh | Auto-installs bash-language-server |
18+
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
19+
| csharp | .cs | `.NET SDK` installed |
20+
| dart | .dart | `dart` command available |
21+
| deno | .ts, .tsx, .js, .jsx, .mjs | `deno` command available (auto-detects deno.json/deno.jsonc) |
22+
| elixir-ls | .ex, .exs | `elixir` command available |
23+
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | `eslint` dependency in project |
24+
| fsharp | .fs, .fsi, .fsx, .fsscript | `.NET SDK` installed |
25+
| gleam | .gleam | `gleam` command available |
26+
| gopls | .go | `go` command available |
27+
| jdtls | .java | `Java SDK (version 21+)` installed |
28+
| lua-ls | .lua | Auto-installs for Lua projects |
29+
| ocaml-lsp | .ml, .mli | `ocamllsp` command available |
30+
| oxlint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte | `oxlint` dependency in project |
31+
| php intelephense | .php | Auto-installs for PHP projects |
32+
| pyright | .py, .pyi | `pyright` dependency installed |
33+
| ruby-lsp (rubocop) | .rb, .rake, .gemspec, .ru | `ruby` and `gem` commands available |
34+
| rust | .rs | `rust-analyzer` command available |
35+
| sourcekit-lsp | .swift, .objc, .objcpp | `swift` installed (`xcode` on macOS) |
36+
| svelte | .svelte | Auto-installs for Svelte projects |
37+
| terraform | .tf, .tfvars | Auto-installs from GitHub releases |
38+
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | `typescript` dependency in project |
39+
| vue | .vue | Auto-installs for Vue projects |
40+
| yaml-ls | .yaml, .yml | Auto-installs Red Hat yaml-language-server |
41+
| zls | .zig, .zon | `zig` command available |
4142

4243
LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.
4344

0 commit comments

Comments
 (0)