Skip to main content

Module panic_guard

Module panic_guard 

Source
Expand description

Wrap async LSP handler bodies so a panic in one request doesn’t terminate the server connection. tower-lsp 0.20 does not catch handler panics by default; a single bad request would otherwise kill the editor’s LSP session and lose unsaved client-side state.

Usage:

async fn hover(&self, params: HoverParams) -> Result<Option<Hover>> {
    guard_async("hover", async move {
        // existing handler body
        Ok(...)
    })
    .await
}

On panic the closure returns R::default(), which for the LSP handler types we care about is Ok(None) / Ok(Vec::new()) / () — the editor sees an empty response, not a closed connection.

Functions§

guard_async
Run fut with panic isolation. On panic, log and return the default value of R. Use for notification handlers (return ()) and other places where R: Default directly applies.
guard_async_result
Run fut that returns Result<R, E> with panic isolation. On panic, log and return Ok(R::default()) so the LSP client gets a graceful empty response (typically null / empty list) instead of seeing the connection closed.