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

# Language Server Protocol

> Register language server providers for custom languages

Extensions can register Language Server Protocol (LSP) providers to add language support for syntax highlighting, code completion, diagnostics, and more.

## LanguageServerRegistry

```kotlin theme={null}
private val languageServers: LanguageServerRegistry by plugin()
```

### Register a provider

```kotlin theme={null}
val registration = languageServers.register(
    this,
    extension = "mylang",
    provider = LanguageServerProvider { client ->
        // Start and return a LanguageServer instance
        MyLanguageServer(client)
    }
)
```

The `extension` parameter is the file extension (without dot) that this server handles. Klyx will start the server when the user opens a file with this extension.

### Unregister a provider

```kotlin theme={null}
registration.unregister()
// or
languageServers.unregister("mylang")
```

### Check for a provider

```kotlin theme={null}
val provider: LanguageServerProvider? = languageServers.getProvider("mylang")
```

## LanguageServerProvider

```kotlin theme={null}
fun interface LanguageServerProvider {
    suspend fun startServer(client: LanguageClient): LanguageServer
}
```

Your implementation should:

1. Accept a `LanguageClient` (used to send notifications/requests to the editor)
2. Start your language server (e.g., via a subprocess, embedded JVM, WASM, etc.)
3. Return a `LanguageServer` instance that the editor uses to send requests

## LanguageServerRegistration

```kotlin theme={null}
interface LanguageServerRegistration {
    fun unregister()
}
```

## Important notes

* The LSP API requires a working LSP server binary. You may need to bundle one or download it at runtime.
* The server process handles requests from Klyx for the associated file type.
* Klyx manages the server lifecycle — starting it when needed and stopping it when the file is closed.
