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
futwith panic isolation. On panic, log and return the default value ofR. Use for notification handlers (return()) and other places whereR: Defaultdirectly applies. - guard_
async_ result - Run
futthat returnsResult<R, E>with panic isolation. On panic, log and returnOk(R::default())so the LSP client gets a graceful empty response (typicallynull/ empty list) instead of seeing the connection closed.