> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/anomalyco/opencode/llms.txt
> Use this file to discover all available pages before exploring further.

# LSP Servers

> OpenCode integrates with Language Server Protocol (LSP) servers to provide intelligent code analysis and diagnostics.

OpenCode integrates with your Language Server Protocol (LSP) servers to help the LLM interact with your codebase. It uses diagnostics to provide feedback to the LLM, enabling intelligent code understanding and error detection.

## Built-in LSP Servers

OpenCode comes with several built-in LSP servers for popular languages:

| LSP Server         | Extensions                                                          | Requirements                                                 |
| ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------ |
| astro              | .astro                                                              | Auto-installs for Astro projects                             |
| bash               | .sh, .bash, .zsh, .ksh                                              | Auto-installs bash-language-server                           |
| clangd             | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++                | Auto-installs for C/C++ projects                             |
| csharp             | .cs                                                                 | `.NET SDK` installed                                         |
| clojure-lsp        | .clj, .cljs, .cljc, .edn                                            | `clojure-lsp` command available                              |
| dart               | .dart                                                               | `dart` command available                                     |
| deno               | .ts, .tsx, .js, .jsx, .mjs                                          | `deno` command available (auto-detects deno.json/deno.jsonc) |
| elixir-ls          | .ex, .exs                                                           | `elixir` command available                                   |
| eslint             | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue                  | `eslint` dependency in project                               |
| fsharp             | .fs, .fsi, .fsx, .fsscript                                          | `.NET SDK` installed                                         |
| gleam              | .gleam                                                              | `gleam` command available                                    |
| gopls              | .go                                                                 | `go` command available                                       |
| hls                | .hs, .lhs                                                           | `haskell-language-server-wrapper` command available          |
| jdtls              | .java                                                               | `Java SDK (version 21+)` installed                           |
| julials            | .jl                                                                 | `julia` and `LanguageServer.jl` installed                    |
| kotlin-ls          | .kt, .kts                                                           | Auto-installs for Kotlin projects                            |
| lua-ls             | .lua                                                                | Auto-installs for Lua projects                               |
| nixd               | .nix                                                                | `nixd` command available                                     |
| ocaml-lsp          | .ml, .mli                                                           | `ocamllsp` command available                                 |
| oxlint             | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte | `oxlint` dependency in project                               |
| php intelephense   | .php                                                                | Auto-installs for PHP projects                               |
| prisma             | .prisma                                                             | `prisma` command available                                   |
| pyright            | .py, .pyi                                                           | `pyright` dependency installed                               |
| ruby-lsp (rubocop) | .rb, .rake, .gemspec, .ru                                           | `ruby` and `gem` commands available                          |
| rust               | .rs                                                                 | `rust-analyzer` command available                            |
| sourcekit-lsp      | .swift, .objc, .objcpp                                              | `swift` installed (`xcode` on macOS)                         |
| svelte             | .svelte                                                             | Auto-installs for Svelte projects                            |
| terraform          | .tf, .tfvars                                                        | Auto-installs from GitHub releases                           |
| tinymist           | .typ, .typc                                                         | Auto-installs from GitHub releases                           |
| typescript         | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts                        | `typescript` dependency in project                           |
| vue                | .vue                                                                | Auto-installs for Vue projects                               |
| yaml-ls            | .yaml, .yml                                                         | Auto-installs Red Hat yaml-language-server                   |
| zls                | .zig, .zon                                                          | `zig` command available                                      |

LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.

<Note>
  You can disable automatic LSP server downloads by setting the `OPENCODE_DISABLE_LSP_DOWNLOAD` environment variable to `true`.
</Note>

## How It Works

When OpenCode opens a file, it:

<Steps>
  <Step title="Detect file extension">
    Checks the file extension against all enabled LSP servers.
  </Step>

  <Step title="Start LSP server">
    Starts the appropriate LSP server if not already running.
  </Step>

  <Step title="Provide diagnostics">
    The LSP server provides real-time diagnostics and code intelligence to the LLM.
  </Step>
</Steps>

## Configuration

You can customize LSP servers through the `lsp` section in your OpenCode config.

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {}
}
```

Each LSP server supports the following properties:

| Property         | Type      | Description                                       |
| ---------------- | --------- | ------------------------------------------------- |
| `disabled`       | boolean   | Set this to `true` to disable the LSP server      |
| `command`        | string\[] | The command to start the LSP server               |
| `extensions`     | string\[] | File extensions this LSP server should handle     |
| `env`            | object    | Environment variables to set when starting server |
| `initialization` | object    | Initialization options to send to the LSP server  |

### Environment Variables

Use the `env` property to set environment variables when starting the LSP server:

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "rust": {
      "env": {
        "RUST_LOG": "debug"
      }
    }
  }
}
```

### Initialization Options

Use the `initialization` property to pass initialization options to the LSP server. These are server-specific settings sent during the LSP `initialize` request:

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "typescript": {
      "initialization": {
        "preferences": {
          "importModuleSpecifierPreference": "relative"
        }
      }
    }
  }
}
```

<Note>
  Initialization options vary by LSP server. Check your LSP server's documentation for available options.
</Note>

### Disabling LSP Servers

To disable **all** LSP servers globally, set `lsp` to `false`:

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": false
}
```

To disable a **specific** LSP server, set `disabled` to `true`:

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "typescript": {
      "disabled": true
    }
  }
}
```

### Custom LSP Servers

You can add custom LSP servers by specifying the command and file extensions:

```json title="opencode.json" theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "custom-lsp": {
      "command": ["custom-lsp-server", "--stdio"],
      "extensions": [".custom"]
    }
  }
}
```

## Additional Information

### PHP Intelephense

PHP Intelephense offers premium features through a license key. You can provide a license key by placing (only) the key in a text file at:

* On macOS/Linux: `$HOME/intelephense/license.txt`
* On Windows: `%USERPROFILE%/intelephense/license.txt`

The file should contain only the license key with no additional content.

## FAQ

<AccordionGroup>
  <Accordion title="How do I check which LSP servers are running?">
    You can check the status of LSP servers by examining the diagnostics in your OpenCode session. Active LSP servers will provide real-time feedback on errors and warnings in your code.
  </Accordion>

  <Accordion title="Can I use multiple LSP servers for the same file?">
    Yes, OpenCode can run multiple LSP servers for the same file if their extension patterns match. For example, both `typescript` and `eslint` can run for `.ts` files.
  </Accordion>

  <Accordion title="What happens if an LSP server fails to start?">
    If an LSP server fails to start, OpenCode will log the error and mark the server as broken for that session. You can check your configuration and requirements to troubleshoot the issue.
  </Accordion>

  <Accordion title="How do I disable LSP downloads in restricted environments?">
    Set the `OPENCODE_DISABLE_LSP_DOWNLOAD` environment variable to `true`. You'll need to manually install any required LSP servers.
  </Accordion>
</AccordionGroup>
