Skip to content

Commit b7ef0c2

Browse files
committed
feat: support astro lsp
1 parent b7c8690 commit b7ef0c2

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

packages/opencode/src/lsp/language.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
9999
".vue": "vue",
100100
".zig": "zig",
101101
".zon": "zig",
102+
".astro": "astro",
102103
} as const

packages/opencode/src/lsp/server.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,46 @@ export namespace LSPServer {
701701
},
702702
}
703703

704+
export const Astro: Info = {
705+
id: "astro",
706+
extensions: [".astro"],
707+
root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]),
708+
async spawn(root) {
709+
let binary = Bun.which("astro-ls")
710+
const args: string[] = []
711+
if (!binary) {
712+
const js = path.join(Global.Path.bin, "node_modules", "@astrojs", "language-server", "bin", "nodeServer.js")
713+
if (!(await Bun.file(js).exists())) {
714+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
715+
await Bun.spawn([BunProc.which(), "install", "@astrojs/language-server"], {
716+
cwd: Global.Path.bin,
717+
env: {
718+
...process.env,
719+
BUN_BE_BUN: "1",
720+
},
721+
stdout: "pipe",
722+
stderr: "pipe",
723+
stdin: "pipe",
724+
}).exited
725+
}
726+
binary = BunProc.which()
727+
args.push("run", js)
728+
}
729+
args.push("--stdio")
730+
const proc = spawn(binary, args, {
731+
cwd: root,
732+
env: {
733+
...process.env,
734+
BUN_BE_BUN: "1",
735+
},
736+
})
737+
return {
738+
process: proc,
739+
initialization: {},
740+
}
741+
},
742+
}
743+
704744
export const JDTLS: Info = {
705745
id: "jdtls",
706746
root: NearestRoot(["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"]),

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
| rust | .rs | `rust-analyzer` command available |
2727
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
2828
| svelte | .svelte | Auto-installs for Svelte projects |
29+
| astro | .astro | Auto-installs for Astro projects |
2930
| jdtls | .java | `Java SDK (version 21+)` installed |
3031

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

0 commit comments

Comments
 (0)