Skip to content

Commit 92d9a0e

Browse files
hugiexhiunguynxopencode-agent[bot]
authored
feat: deno lsp (#3210)
Co-authored-by: hiunguynx <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
1 parent 2be9ed2 commit 92d9a0e

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

packages/opencode/src/lsp/server.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@ export namespace LSPServer {
2020

2121
type RootFunction = (file: string) => Promise<string | undefined>
2222

23-
const NearestRoot = (patterns: string[]): RootFunction => {
23+
const NearestRoot = (includePatterns: string[], excludePatterns?: string[]): RootFunction => {
2424
return async (file) => {
25+
if (excludePatterns) {
26+
const excludedFiles = Filesystem.up({
27+
targets: excludePatterns,
28+
start: path.dirname(file),
29+
stop: Instance.directory,
30+
})
31+
const excluded = await excludedFiles.next()
32+
await excludedFiles.return()
33+
if (excluded.value) return undefined
34+
}
2535
const files = Filesystem.up({
26-
targets: patterns,
36+
targets: includePatterns,
2737
start: path.dirname(file),
2838
stop: Instance.directory,
2939
})
@@ -42,9 +52,30 @@ export namespace LSPServer {
4252
spawn(root: string): Promise<Handle | undefined>
4353
}
4454

55+
export const Deno: Info = {
56+
id: "deno",
57+
root: NearestRoot(["deno.json", "deno.jsonc"]),
58+
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs"],
59+
async spawn(root) {
60+
const deno = Bun.which("deno")
61+
if (!deno) {
62+
log.info("deno not found, please install deno first")
63+
return
64+
}
65+
return {
66+
process: spawn(deno, ["lsp"], {
67+
cwd: root,
68+
}),
69+
}
70+
},
71+
}
72+
4573
export const Typescript: Info = {
4674
id: "typescript",
47-
root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
75+
root: NearestRoot(
76+
["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"],
77+
["deno.json", "deno.jsonc"],
78+
),
4879
extensions: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"],
4980
async spawn(root) {
5081
const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ 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-
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | `typescript` dependency in project |
17-
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | `eslint` dependency in project |
18-
| gopls | .go | `go` command available |
19-
| ruby-lsp | .rb, .rake, .gemspec, .ru | `ruby` and `gem` commands available |
20-
| pyright | .py, .pyi | `pyright` dependency installed |
21-
| elixir-ls | .ex, .exs | `elixir` command available |
22-
| zls | .zig, .zon | `zig` command available |
23-
| csharp | .cs | `.NET SDK` installed |
24-
| vue | .vue | Auto-installs for Vue projects |
25-
| rust | .rs | `rust-analyzer` command available |
26-
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
27-
| svelte | .svelte | Auto-installs for Svelte projects |
28-
| jdtls | .java | `Java SDK (version 21+)` installed |
14+
| LSP Server | Extensions | Requirements |
15+
| ---------- | ---------------------------------------------------- | ------------------------------------------------------------ |
16+
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | `typescript` dependency in project |
17+
| deno | .ts, .tsx, .js, .jsx, .mjs | `deno` command available (auto-detects deno.json/deno.jsonc) |
18+
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | `eslint` dependency in project |
19+
| gopls | .go | `go` command available |
20+
| ruby-lsp | .rb, .rake, .gemspec, .ru | `ruby` and `gem` commands available |
21+
| pyright | .py, .pyi | `pyright` dependency installed |
22+
| elixir-ls | .ex, .exs | `elixir` command available |
23+
| zls | .zig, .zon | `zig` command available |
24+
| csharp | .cs | `.NET SDK` installed |
25+
| vue | .vue | Auto-installs for Vue projects |
26+
| rust | .rs | `rust-analyzer` command available |
27+
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
28+
| svelte | .svelte | Auto-installs for Svelte projects |
29+
| jdtls | .java | `Java SDK (version 21+)` installed |
2930

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

0 commit comments

Comments
 (0)