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-term/src/application.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'helix-term/src/application.rs') diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 4eda8097..01c120d0 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -27,7 +27,7 @@ use crate::{ ui::{self, overlay::overlaid}, }; -use log::{debug, error, warn}; +use log::{debug, error, info, warn}; #[cfg(not(feature = "integration"))] use std::io::stdout; use std::{collections::btree_map::Entry, io::stdin, path::Path, sync::Arc}; @@ -683,9 +683,13 @@ impl Application { Call::Notification(helix_lsp::jsonrpc::Notification { method, params, .. }) => { let notification = match Notification::parse(&method, params) { Ok(notification) => notification, + Err(helix_lsp::Error::Unhandled) => { + info!("Ignoring Unhandled notification from Language Server"); + return; + } Err(err) => { - log::error!( - "received malformed notification from Language Server: {}", + error!( + "Ignoring unknown notification from Language Server: {}", err ); return; -- cgit v1.2.3-70-g09d2