Browse Source

Adding LSP: PHP Intelephense (#4504)

Co-authored-by: Aiden Cline <[email protected]>
Daniel Polito 3 months ago
parent
commit
e1089bc5de
2 changed files with 74 additions and 20 deletions
  1. 40 0
      packages/opencode/src/lsp/server.ts
  2. 34 20
      packages/web/src/content/docs/lsp.mdx

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

@@ -1125,4 +1125,44 @@ export namespace LSPServer {
       }
       }
     },
     },
   }
   }
+
+  export const PHPIntelephense: Info = {
+    id: "php intelephense",
+    extensions: [".php"],
+    root: NearestRoot(["composer.json", "composer.lock", ".php-version"]),
+    async spawn(root) {
+      let binary = Bun.which("intelephense")
+      const args: string[] = []
+      if (!binary) {
+        const js = path.join(Global.Path.bin, "node_modules", "intelephense", "lib", "intelephense.js")
+        if (!(await Bun.file(js).exists())) {
+          if (Flag.OPENCODE_DISABLE_LSP_DOWNLOAD) return
+          await Bun.spawn([BunProc.which(), "install", "intelephense"], {
+            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: {},
+      }
+    },
+  }
 }
 }

+ 34 - 20
packages/web/src/content/docs/lsp.mdx

@@ -11,26 +11,27 @@ OpenCode integrates with your Language Server Protocol (LSP) to help the LLM int
 
 
 OpenCode comes with several built-in LSP servers for popular languages:
 OpenCode comes with several built-in LSP servers for popular languages:
 
 
-| LSP Server    | Extensions                                           | Requirements                                                 |
-| ------------- | ---------------------------------------------------- | ------------------------------------------------------------ |
-| typescript    | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts         | `typescript` dependency in project                           |
-| deno          | .ts, .tsx, .js, .jsx, .mjs                           | `deno` command available (auto-detects deno.json/deno.jsonc) |
-| eslint        | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue   | `eslint` dependency in project                               |
-| gopls         | .go                                                  | `go` command available                                       |
-| ruby-lsp      | .rb, .rake, .gemspec, .ru                            | `ruby` and `gem` commands available                          |
-| pyright       | .py, .pyi                                            | `pyright` dependency installed                               |
-| elixir-ls     | .ex, .exs                                            | `elixir` command available                                   |
-| zls           | .zig, .zon                                           | `zig` command available                                      |
-| csharp        | .cs                                                  | `.NET SDK` installed                                         |
-| 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                            |
-| astro         | .astro                                               | Auto-installs for Astro projects                             |
-| yaml-ls       | .yaml, .yml                                          | Auto-installs Red Hat yaml-language-server                   |
-| jdtls         | .java                                                | `Java SDK (version 21+)` installed                           |
-| lua-ls        | .lua                                                 | Auto-installs for Lua projects                               |
-| sourcekit-lsp | .swift, .objc, .objcpp                               | `swift` installed (`xcode` on macOS)                         |
+| LSP Server       | Extensions                                           | Requirements                                                 |
+| ---------------- | ---------------------------------------------------- | ------------------------------------------------------------ |
+| typescript       | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts         | `typescript` dependency in project                           |
+| deno             | .ts, .tsx, .js, .jsx, .mjs                           | `deno` command available (auto-detects deno.json/deno.jsonc) |
+| eslint           | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue   | `eslint` dependency in project                               |
+| gopls            | .go                                                  | `go` command available                                       |
+| ruby-lsp         | .rb, .rake, .gemspec, .ru                            | `ruby` and `gem` commands available                          |
+| pyright          | .py, .pyi                                            | `pyright` dependency installed                               |
+| elixir-ls        | .ex, .exs                                            | `elixir` command available                                   |
+| zls              | .zig, .zon                                           | `zig` command available                                      |
+| csharp           | .cs                                                  | `.NET SDK` installed                                         |
+| 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                            |
+| astro            | .astro                                               | Auto-installs for Astro projects                             |
+| yaml-ls          | .yaml, .yml                                          | Auto-installs Red Hat yaml-language-server                   |
+| jdtls            | .java                                                | `Java SDK (version 21+)` installed                           |
+| lua-ls           | .lua                                                 | Auto-installs for Lua projects                               |
+| sourcekit-lsp    | .swift, .objc, .objcpp                               | `swift` installed (`xcode` on macOS)                         |
+| php intelephense | .php                                                 | Auto-installs for PHP 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.
 
 
@@ -106,3 +107,16 @@ You can add custom LSP servers by specifying the command and file extensions:
   }
   }
 }
 }
 ```
 ```
+
+---
+
+## Additional Information
+
+### PHP Intelephense
+
+PHP Intelephense offers premium features through a license key. Uou can provide a license key by placing (only) the key in a text file at:
+
+- On macOS/Linux: `$HOME/intelephense/licence.txt`
+- On Windows: `%USERPROFILE%/intelephense/licence.txt`
+
+The file should contain only the license key with no additional content.