@@ -81,6 +81,7 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
".zsh": "shellscript",
".ksh": "shellscript",
".sql": "sql",
+ ".svelte": "svelte",
".swift": "swift",
".ts": "typescript",
".tsx": "typescriptreact",
@@ -654,4 +654,56 @@ export namespace LSPServer {
}
},
+
+ export const Svelte: Info = {
+ id: "svelte",
+ extensions: [".svelte"],
+ root: NearestRoot([
+ "tsconfig.json",
+ "jsconfig.json",
+ "package.json",
+ "pnpm-lock.yaml",
+ "yarn.lock",
+ "bun.lockb",
+ "bun.lock",
+ "vite.config.ts",
+ "vite.config.js",
+ "svelte.config.ts",
+ "svelte.config.js",
+ ]),
+ async spawn(root) {
+ let binary = Bun.which("svelteserver")
+ const args: string[] = []
+ if (!binary) {
+ const js = path.join(Global.Path.bin, "node_modules", "svelte-language-server", "bin", "server.js")
+ if (!(await Bun.file(js).exists())) {
+ if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
+ await Bun.spawn([BunProc.which(), "install", "svelte-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,
+ })
+ return {
+ process: proc,
+ initialization: {},
@@ -24,6 +24,7 @@ opencode comes with several built-in LSP servers for popular languages:
| vue | .vue | Auto-installs for Vue projects |
| 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 |
LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.