Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
lsp: Reduce lsp log spam for unimportant failures (#55732)
Lukas Wirthec0fb05a44b9
diff --git a/crates/editor/src/lsp_ext.rs b/crates/editor/src/lsp_ext.rsindex 60f0dd305ef..881c14903b2 100644--- a/crates/editor/src/lsp_ext.rs+++ b/crates/editor/src/lsp_ext.rs@@ -3,9 +3,9 @@ use std::time::Duration;use crate::Editor;use collections::{HashMap, HashSet};-use futures_lite::FutureExt as _;-use gpui::AsyncApp;+use futures::TryFutureExt;use gpui::{App, Entity, Task};+use gpui::{AsyncApp, FutureExt};use language::Buffer;use language::Language;use lsp::LanguageServerId;@@ -172,14 +172,10 @@ pub fn lsp_tasks(}lsp_tasks.into_iter().collect()})- .race({- // `lsp::DEFAULT_LSP_REQUEST_TIMEOUT` is larger than we want for the modal to open fast- let timer = cx.background_executor().timer(Duration::from_millis(200));- async move {- timer.await;- log::info!("Timed out waiting for LSP tasks");- Vec::new()- }+ .with_timeout(Duration::from_millis(200), &cx.background_executor())+ .unwrap_or_else(|_| {+ log::debug!("Timed out waiting for LSP tasks");+ Vec::new()}).await})diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rsindex 01aab2be7ac..ad3344fa25a 100644--- a/crates/project/src/lsp_store.rs+++ b/crates/project/src/lsp_store.rs@@ -4148,6 +4148,12 @@ impl SymbolLocation {}}+fn should_log_lsp_request_failure(message: &str) -> bool {+ // content modified is a weird failure mode of rust-analyzer+ // where requests are denied before its loaded a project+ message.ends_with("content modified") || message.ends_with("server cancelled the request")+}+impl LspStore {pub fn init(client: &AnyProtoClient) {client.add_entity_request_handler(Self::handle_lsp_query);@@ -5249,8 +5255,7 @@ impl LspStore {language_server.name(),err);- // rust-analyzer likes to error with this when its still loading up- if !message.ends_with("content modified") {+ if should_log_lsp_request_failure(&message) {log::warn!("{message}");}return Task::ready(Err(anyhow!(message)));@@ -5311,8 +5316,7 @@ impl LspStore {language_server.name(),err);- // rust-analyzer likes to error with this when its still loading up- if !message.ends_with("content modified") {+ if should_log_lsp_request_failure(&message) {log::warn!("{message}");}anyhow::anyhow!(message)@@ -7561,8 +7565,15 @@ impl LspStore {) -> Task<anyhow::Result<()>> {let diagnostics = self.pull_diagnostics(buffer, cx);cx.spawn(async move |lsp_store, cx| {- let Some(diagnostics) = diagnostics.await.context("pulling diagnostics")? else {- return Ok(());+ let diagnostics = match diagnostics.await {+ Ok(Some(diagnostics)) => diagnostics,+ Ok(None) => return Ok(()),+ Err(error) if should_log_lsp_request_failure(&format!("{error:#}")) => {+ return Err(error).context("pulling diagnostics");+ }+ // This is a weird way to suppress diagnostic failures on server side cancellation,+ // we should actually retry the request here?+ Err(_) => return Ok(()),};lsp_store.update(cx, |lsp_store, cx| {if lsp_store.as_local().is_none() {