lsp.mdx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ---
  2. title: "LSP"
  3. description: ""
  4. ---
  5. Language Server Protocol (LSP) integrations can provide code diagnostics,
  6. symbols, definitions, references, and other language-aware context.
  7. <Callout type="warning">
  8. OpenCode V2 does not yet have an LSP runtime or built-in language servers. The `lsp` configuration is accepted and
  9. preserved, but it does not currently start or download servers, expose an LSP tool, or add diagnostics to file tool
  10. results.
  11. </Callout>
  12. ## Built-in servers
  13. There are no built-in LSP servers in the current V2 implementation. Setting
  14. `lsp` to `true` declares that built-ins should be enabled, but has no runtime
  15. effect until V2 provides a server registry and LSP runtime.
  16. ```jsonc title="opencode.jsonc"
  17. {
  18. "$schema": "https://opencode.ai/config.json",
  19. "lsp": true,
  20. }
  21. ```
  22. ## Configuration
  23. The `lsp` field accepts a boolean or an object keyed by server name:
  24. ```jsonc title="opencode.jsonc"
  25. {
  26. "$schema": "https://opencode.ai/config.json",
  27. "lsp": {
  28. "custom-typescript": {
  29. "command": ["typescript-language-server", "--stdio"],
  30. "extensions": [".ts", ".tsx"],
  31. "env": {
  32. "TSS_LOG": "-level verbose",
  33. },
  34. "initialization": {
  35. "preferences": {
  36. "importModuleSpecifierPreference": "relative",
  37. },
  38. },
  39. },
  40. },
  41. }
  42. ```
  43. Each enabled server entry has this shape:
  44. | Property | Type | Required | Description |
  45. | ---------------- | ------------------------- | -------- | --------------------------------------------------------------------------------------------- |
  46. | `command` | `string[]` | Yes | Executable followed by any arguments. |
  47. | `extensions` | `string[]` | No | File extensions associated with the server, including the leading dot. |
  48. | `disabled` | `boolean` | No | Disables the entry when `true`. |
  49. | `env` | `Record<string, string>` | No | Environment variables for the server process. The property is named `env`, not `environment`. |
  50. | `initialization` | `Record<string, unknown>` | No | Server-specific options for the LSP `initialize` request. |
  51. The only entry that may omit `command` is the disable-only form:
  52. ```jsonc
  53. {
  54. "lsp": {
  55. "typescript": {
  56. "disabled": true,
  57. },
  58. },
  59. }
  60. ```
  61. Server names are arbitrary. The V2 schema permits `extensions` to be omitted,
  62. including for a custom server, although a future runtime will need a way to
  63. associate that server with files.
  64. ## Disable LSP
  65. Omit `lsp` when no configuration is needed. Set it to `false` to explicitly
  66. disable the whole integration, including when a lower-priority configuration
  67. set it to `true` or supplied an object:
  68. ```jsonc title="opencode.jsonc"
  69. {
  70. "$schema": "https://opencode.ai/config.json",
  71. "lsp": false,
  72. }
  73. ```
  74. Use `{ "disabled": true }` under a server name to disable one server while
  75. retaining the object form. `OPENCODE_DISABLE_LSP_DOWNLOAD` is not used by V2;
  76. V2 currently performs no automatic LSP downloads.
  77. ## Current usage
  78. V2 loads and validates the configuration shape for compatibility and future
  79. integration. It does not currently use LSP when reading, writing, editing, or
  80. patching files, and those tools do not notify a language server or return LSP
  81. diagnostics.
  82. For reliable feedback today, have the agent run the project's lint, typecheck,
  83. test, or compiler commands. Record those commands in an `AGENTS.md` file or a
  84. skill so the agent knows when and where to run them.