Skip to content

Commit 4d8268c

Browse files
authored
feat: support astro lsp (#3242)
1 parent 95d413b commit 4d8268c

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,57 @@ 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+
const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {})
710+
if (!tsserver) {
711+
log.info("typescript not found, required for Astro language server")
712+
return
713+
}
714+
const tsdk = path.dirname(tsserver)
715+
716+
let binary = Bun.which("astro-ls")
717+
const args: string[] = []
718+
if (!binary) {
719+
const js = path.join(Global.Path.bin, "node_modules", "@astrojs", "language-server", "bin", "nodeServer.js")
720+
if (!(await Bun.file(js).exists())) {
721+
if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
722+
await Bun.spawn([BunProc.which(), "install", "@astrojs/language-server"], {
723+
cwd: Global.Path.bin,
724+
env: {
725+
...process.env,
726+
BUN_BE_BUN: "1",
727+
},
728+
stdout: "pipe",
729+
stderr: "pipe",
730+
stdin: "pipe",
731+
}).exited
732+
}
733+
binary = BunProc.which()
734+
args.push("run", js)
735+
}
736+
args.push("--stdio")
737+
const proc = spawn(binary, args, {
738+
cwd: root,
739+
env: {
740+
...process.env,
741+
BUN_BE_BUN: "1",
742+
},
743+
})
744+
return {
745+
process: proc,
746+
initialization: {
747+
typescript: {
748+
tsdk,
749+
},
750+
},
751+
}
752+
},
753+
}
754+
704755
export const JDTLS: Info = {
705756
id: "jdtls",
706757
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)