Skip to content

Commit ac4b8d6

Browse files
authored
feat: add nixd as lsp for nix language (anomalyco#5929)
1 parent 236ce7a commit ac4b8d6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

packages/opencode/src/lsp/language.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
110110
".tf": "terraform",
111111
".tfvars": "terraform-vars",
112112
".hcl": "hcl",
113+
".nix": "nix",
113114
} as const

packages/opencode/src/lsp/server.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,4 +1746,35 @@ export namespace LSPServer {
17461746
}
17471747
},
17481748
}
1749+
1750+
export const Nixd: Info = {
1751+
id: "nixd",
1752+
extensions: [".nix"],
1753+
root: async (file) => {
1754+
// First, look for flake.nix - the most reliable Nix project root indicator
1755+
const flakeRoot = await NearestRoot(["flake.nix"])(file)
1756+
if (flakeRoot && flakeRoot !== Instance.directory) return flakeRoot
1757+
1758+
// If no flake.nix, fall back to git repository root
1759+
if (Instance.worktree && Instance.worktree !== Instance.directory) return Instance.worktree
1760+
1761+
// Finally, use the instance directory as fallback
1762+
return Instance.directory
1763+
},
1764+
async spawn(root) {
1765+
const nixd = Bun.which("nixd")
1766+
if (!nixd) {
1767+
log.info("nixd not found, please install nixd first")
1768+
return
1769+
}
1770+
return {
1771+
process: spawn(nixd, [], {
1772+
cwd: root,
1773+
env: {
1774+
...process.env,
1775+
},
1776+
}),
1777+
}
1778+
},
1779+
}
17491780
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OpenCode comes with several built-in LSP servers for popular languages:
2626
| gopls | .go | `go` command available |
2727
| jdtls | .java | `Java SDK (version 21+)` installed |
2828
| lua-ls | .lua | Auto-installs for Lua projects |
29+
| nixd | .nix | `nixd` command available |
2930
| ocaml-lsp | .ml, .mli | `ocamllsp` command available |
3031
| oxlint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte | `oxlint` dependency in project |
3132
| php intelephense | .php | Auto-installs for PHP projects |

0 commit comments

Comments
 (0)