madflow 5 месяцев назад
Родитель
Сommit
32b47fcc1e

+ 1 - 0
packages/opencode/src/lsp/language.ts

@@ -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",

+ 52 - 0
packages/opencode/src/lsp/server.ts

@@ -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: {},
+      }
+    },
+  }
 }
 }

+ 1 - 0
packages/web/src/content/docs/lsp.mdx

@@ -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.