From 4b59c3a538f27238b0466898f1b4ac69d1f9e778 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 28 Jan 2021 17:04:44 +0300 Subject: [PATCH] Make logger-based debugging more pleasant --- crates/flycheck/src/lib.rs | 16 +++++++++++++++- crates/project_model/src/workspace.rs | 5 +++-- crates/rust-analyzer/src/reload.rs | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 4388e8c6735..e04208006fe 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -76,7 +76,6 @@ pub fn update(&self) { } } -#[derive(Debug)] pub enum Message { /// Request adding a diagnostic with fixes included to a file AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic }, @@ -89,6 +88,21 @@ pub enum Message { }, } +impl fmt::Debug for Message { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Message::AddDiagnostic { workspace_root, diagnostic } => f + .debug_struct("AddDiagnostic") + .field("workspace_root", workspace_root) + .field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code)) + .finish(), + Message::Progress { id, progress } => { + f.debug_struct("Progress").field("id", id).field("progress", progress).finish() + } + } + } +} + #[derive(Debug)] pub enum Progress { DidStart, diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index bc5041e5a3d..559f4e7bf6e 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -51,6 +51,7 @@ pub enum ProjectWorkspace { impl fmt::Debug for ProjectWorkspace { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Make sure this isn't too verbose. match self { ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } => f .debug_struct("Cargo") @@ -60,7 +61,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "n_rustc_compiler_crates", &rustc.as_ref().map_or(0, |rc| rc.packages().len()), ) - .field("rustc_cfg", rustc_cfg) + .field("n_rustc_cfg", &rustc_cfg.len()) .finish(), ProjectWorkspace::Json { project, sysroot, rustc_cfg } => { let mut debug_struct = f.debug_struct("Json"); @@ -68,7 +69,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(sysroot) = sysroot { debug_struct.field("n_sysroot_crates", &sysroot.crates().len()); } - debug_struct.field("rustc_cfg", rustc_cfg); + debug_struct.field("n_rustc_cfg", &rustc_cfg.len()); debug_struct.finish() } } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 0507186dce5..ef73099cfae 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -103,10 +103,10 @@ pub(crate) fn fetch_workspaces_request(&mut self) { self.fetch_workspaces_queue.request_op() } pub(crate) fn fetch_workspaces_if_needed(&mut self) { - log::info!("will fetch workspaces"); if !self.fetch_workspaces_queue.should_start_op() { return; } + log::info!("will fetch workspaces"); self.task_pool.handle.spawn_with_sender({ let linked_projects = self.config.linked_projects();