From dcdecaab22e87ae8046e15aa461dc2604b1c67ad Mon Sep 17 00:00:00 2001 From: Ben Dennis Date: Wed, 17 Jan 2024 08:49:25 -0600 Subject: Exit a language server if it sends a message with invalid json (#9332) * Keep lsp event listener thread alive when malformed json is encountered from the lsp server * Update unexpected error flow in recv() to close outstanding requests and close the language server * Log malformed notifications as info instead of error * Make close_language_server a nested function inside recv, similar to what's done in send * Update malformed notification log text * Clean up new log text a bit * Initialize recv_buffer closer to where it's used * Use "exit" instead of "close" * Remove whitespace * Remove the need for a helper method to exit the language server * Match on Unhandled error explicitly and keep catch-all error case around--- helix-lsp/src/transport.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'helix-lsp') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 9fdd30aa..f2f35d6a 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -270,7 +270,14 @@ impl Transport { } }; } - Err(Error::StreamClosed) => { + Err(err) => { + if !matches!(err, Error::StreamClosed) { + error!( + "Exiting {} after unexpected error: {err:?}", + &transport.name + ); + } + // Close any outstanding requests. for (id, tx) in transport.pending_requests.lock().await.drain() { match tx.send(Err(Error::StreamClosed)).await { @@ -300,10 +307,6 @@ impl Transport { } break; } - Err(err) => { - error!("{} err: <- {err:?}", transport.name); - break; - } } } } -- cgit v1.2.3-70-g09d2