lsp.mdx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ---
  2. title: LSP Servers
  3. description: opencode integrates with your LSP servers.
  4. ---
  5. opencode integrates with your Language Server Protocol (LSP) to help the LLM interact with your codebase. It uses diagnostics to provide feedback to the LLM.
  6. ---
  7. ## Built-in
  8. opencode comes with several built-in LSP servers for popular languages:
  9. | LSP Server | Extensions | Requirements |
  10. | ---------- | ---------------------------------------------------- | ----------------------------------- |
  11. | typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | `typescript` dependency in project |
  12. | eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | `eslint` dependency in project |
  13. | gopls | .go | `go` command available |
  14. | ruby-lsp | .rb, .rake, .gemspec, .ru | `ruby` and `gem` commands available |
  15. | pyright | .py, .pyi | `pyright` dependency installed |
  16. | elixir-ls | .ex, .exs | `elixir` command available |
  17. | zls | .zig, .zon | `zig` command available |
  18. | csharp | .cs | `.NET SDK` installed |
  19. | vue | .vue | Auto-installs for Vue projects |
  20. | rust | .rs | `rust-analyzer` command available |
  21. | clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
  22. | svelte | .svelte | Auto-installs for Svelte projects |
  23. LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.
  24. :::note
  25. You can disable automatic LSP server downloads by setting the `OPENCODE_DISABLE_LSP_DOWNLOAD` environment variable to `true`.
  26. :::
  27. ---
  28. ## How It Works
  29. When opencode opens a file, it:
  30. 1. Checks the file extension against all enabled LSP servers.
  31. 2. Starts the appropriate LSP server if not already running.
  32. ---
  33. ## Configure
  34. You can customize LSP servers through the `lsp` section in your opencode config.
  35. ```json title="opencode.json"
  36. {
  37. "$schema": "https://opencode.ai/config.json",
  38. "lsp": {}
  39. }
  40. ```
  41. Each LSP server supports the following:
  42. | Property | Type | Description |
  43. | ---------------- | -------- | ------------------------------------------------- |
  44. | `disabled` | boolean | Set this to `true` to disable the LSP server |
  45. | `command` | string[] | The command to start the LSP server |
  46. | `extensions` | string[] | File extensions this LSP server should handle |
  47. | `env` | object | Environment variables to set when starting server |
  48. | `initialization` | object | Initialization options to send to the LSP server |
  49. Let's look at some examples.
  50. ---
  51. ### Disabling LSP servers
  52. To disable a specific LSP server, set `disabled` to `true`:
  53. ```json title="opencode.json" {5}
  54. {
  55. "$schema": "https://opencode.ai/config.json",
  56. "lsp": {
  57. "typescript": {
  58. "disabled": true
  59. }
  60. }
  61. }
  62. ```
  63. ---
  64. ### Custom LSP servers
  65. You can add custom LSP servers by specifying the command and file extensions:
  66. ```json title="opencode.json" {4-7}
  67. {
  68. "$schema": "https://opencode.ai/config.json",
  69. "lsp": {
  70. "custom-lsp": {
  71. "command": ["custom-lsp-server", "--stdio"],
  72. "extensions": [".custom"]
  73. }
  74. }
  75. }
  76. ```