From 15466604357494eb8b70b8f7358b0773c5ccc795 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Sun, 21 Jun 2026 22:52:49 +0200 Subject: [PATCH] Fixed initialization error --- analyzer.bat | 2 +- crates/analyzer/src/rust_analyzer.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/analyzer.bat b/analyzer.bat index 8ffbbf8..446d793 100644 --- a/analyzer.bat +++ b/analyzer.bat @@ -4,6 +4,6 @@ cd D:\projects\mist\mist mist build >nul 2>&1 -cd D:\projects\mist\mist-lsp-test +cd mist-test D:\projects\mist\mist\target\debug\mist-analyzer.exe diff --git a/crates/analyzer/src/rust_analyzer.rs b/crates/analyzer/src/rust_analyzer.rs index 2fbee2f..8a4a7d3 100644 --- a/crates/analyzer/src/rust_analyzer.rs +++ b/crates/analyzer/src/rust_analyzer.rs @@ -57,11 +57,16 @@ async fn read_lsp_message( ) -> Result> { let mut line = String::new(); let mut content_length = 0; + let mut eof = false; for _ in 0..100 { line.clear(); let bytes_read = reader.read_line(&mut line).await?; - if bytes_read == 0 || line.trim().is_empty() { + if bytes_read == 0 { + eof = true; + break; + } + if line.trim().is_empty() { break; } if line.to_ascii_lowercase().starts_with("content-length:") { @@ -75,6 +80,9 @@ async fn read_lsp_message( } if content_length == 0 { + if eof { + return Err("LSP stream closed (EOF)".into()); + } return Err("Missing, invalid, or zero Content-Length header".into()); } if content_length > MAX_CONTENT_LENGTH { @@ -126,8 +134,11 @@ impl RustAnalyzer { for (_, tx) in lock.drain() { let _ = tx.send(Err(format!("LSP reader error: {}", err))); } - // Brief backoff then retry — ra may have sent a malformed frame - // but the connection is still alive. + // EOF means the child process exited — stop the reader. + // Other errors (malformed frames) get a brief backoff then retry. + if err.to_string().contains("LSP stream closed (EOF)") { + break; + } tokio::time::sleep(Duration::from_millis(50)).await; continue; }