From 86a8d063ea1453e5d6377299f67ad1a2a363d8c0 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Wed, 6 Jul 2022 20:51:22 +0100 Subject: [PATCH] check if lsp active before reload fix proxy hanging around after stopped --- lapce-proxy/src/lsp.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lapce-proxy/src/lsp.rs b/lapce-proxy/src/lsp.rs index 88851ab2..86072c20 100644 --- a/lapce-proxy/src/lsp.rs +++ b/lapce-proxy/src/lsp.rs @@ -4,7 +4,11 @@ io::{BufReader, BufWriter, Write}, path::Path, process::{self, Child, ChildStdout, Command, Stdio}, - sync::{mpsc::channel, Arc}, + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::channel, + Arc, + }, thread, time::Duration, }; @@ -93,6 +97,7 @@ pub struct LspClient { options: Option, state: Arc>, dispatcher: Dispatcher, + active: Arc, } impl LspCatalog { @@ -534,6 +539,7 @@ pub fn new( is_initialized: false, did_save_capabilities: Vec::new(), })), + active: Arc::new(AtomicBool::new(true)), }); lsp_client.handle_stdout(stdout); @@ -552,6 +558,9 @@ fn handle_stdout(&self, stdout: ChildStdout) { local_lsp_client.handle_message(message_str.as_ref()); } Err(_err) => { + if !local_lsp_client.active.load(Ordering::Acquire) { + return; + } local_lsp_client.stop(); local_lsp_client.reload(); return; @@ -595,6 +604,7 @@ fn reload(&self) { } fn stop(&self) { + self.active.store(false, Ordering::Release); let _ = self.state.lock().process.kill(); }