diff --git a/packages/opencode/src/lsp/language.ts b/packages/opencode/src/lsp/language.ts index 8ab7f48dc5..b7bcd8e912 100644 --- a/packages/opencode/src/lsp/language.ts +++ b/packages/opencode/src/lsp/language.ts @@ -99,4 +99,5 @@ export const LANGUAGE_EXTENSIONS: Record = { ".vue": "vue", ".zig": "zig", ".zon": "zig", + ".astro": "astro", } as const diff --git a/packages/opencode/src/lsp/server.ts b/packages/opencode/src/lsp/server.ts index 68d8c2a934..49b55aba79 100644 --- a/packages/opencode/src/lsp/server.ts +++ b/packages/opencode/src/lsp/server.ts @@ -701,6 +701,57 @@ export namespace LSPServer { }, } + export const Astro: Info = { + id: "astro", + extensions: [".astro"], + root: NearestRoot(["package-lock.json", "bun.lockb", "bun.lock", "pnpm-lock.yaml", "yarn.lock"]), + async spawn(root) { + const tsserver = await Bun.resolve("typescript/lib/tsserver.js", Instance.directory).catch(() => {}) + if (!tsserver) { + log.info("typescript not found, required for Astro language server") + return + } + const tsdk = path.dirname(tsserver) + + let binary = Bun.which("astro-ls") + const args: string[] = [] + if (!binary) { + const js = path.join(Global.Path.bin, "node_modules", "@astrojs", "language-server", "bin", "nodeServer.js") + if (!(await Bun.file(js).exists())) { + if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return + await Bun.spawn([BunProc.which(), "install", "@astrojs/language-server"], { + cwd: Global.Path.bin, + env: { + ...process.env, + BUN_BE_BUN: "1", + }, + stdout: "pipe", + stderr: "pipe", + stdin: "pipe", + }).exited + } + binary = BunProc.which() + args.push("run", js) + } + args.push("--stdio") + const proc = spawn(binary, args, { + cwd: root, + env: { + ...process.env, + BUN_BE_BUN: "1", + }, + }) + return { + process: proc, + initialization: { + typescript: { + tsdk, + }, + }, + } + }, + } + export const JDTLS: Info = { id: "jdtls", root: NearestRoot(["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"]), diff --git a/packages/web/src/content/docs/lsp.mdx b/packages/web/src/content/docs/lsp.mdx index e81fa9cf9d..da7d5dde82 100644 --- a/packages/web/src/content/docs/lsp.mdx +++ b/packages/web/src/content/docs/lsp.mdx @@ -26,6 +26,7 @@ OpenCode comes with several built-in LSP servers for popular languages: | rust | .rs | `rust-analyzer` command available | | clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects | | svelte | .svelte | Auto-installs for Svelte projects | +| astro | .astro | Auto-installs for Astro projects | | jdtls | .java | `Java SDK (version 21+)` installed | LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.