feat: svelte lsp (#2508)

This commit is contained in:
madflow
2025-09-09 20:59:58 +02:00
committed by GitHub
parent fde03d3c93
commit 32b47fcc1e
3 changed files with 54 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
".zsh": "shellscript", ".zsh": "shellscript",
".ksh": "shellscript", ".ksh": "shellscript",
".sql": "sql", ".sql": "sql",
".svelte": "svelte",
".swift": "swift", ".swift": "swift",
".ts": "typescript", ".ts": "typescript",
".tsx": "typescriptreact", ".tsx": "typescriptreact",

View File

@@ -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,
env: {
...process.env,
BUN_BE_BUN: "1",
},
})
return {
process: proc,
initialization: {},
}
},
}
} }

View File

@@ -24,6 +24,7 @@ opencode comes with several built-in LSP servers for popular languages:
| vue | .vue | Auto-installs for Vue projects | | vue | .vue | Auto-installs for Vue projects |
| rust | .rs | `rust-analyzer` command available | | rust | .rs | `rust-analyzer` command available |
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects | | 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. LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.