From 56df0fc83c753b7fb8829438c8d3017ef1bf450c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 25 Oct 2018 16:03:49 +0300 Subject: [PATCH] Improve logging --- Cargo.lock | 8 +++++--- crates/ra_analysis/Cargo.toml | 1 + crates/ra_analysis/src/db/mod.rs | 9 +-------- crates/ra_analysis/src/imp.rs | 2 ++ crates/ra_analysis/src/lib.rs | 19 ++++++++++++++++--- crates/ra_lsp_server/src/main_loop/mod.rs | 20 ++++++++++++++++---- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1a294c302..982463f0b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -602,12 +602,13 @@ name = "ra_analysis" version = "0.1.0" dependencies = [ "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "ra_editor 0.1.0", "ra_syntax 0.1.0", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "salsa 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "test_utils 0.1.0", ] @@ -833,11 +834,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "salsa" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "derive-new 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1348,7 +1350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" -"checksum salsa 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c8f8b59428c040fbac0f6a2e698ae892e33d23d7519713ba8b243edb3082dad" +"checksum salsa 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fc085b9e4a2cf422e798387d0dc1091c6dae97411b2b177755950db9a26dace" "checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index 75a9dc8441..b9f9cd7a70 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml @@ -5,6 +5,7 @@ version = "0.1.0" authors = ["Aleksey Kladov "] [dependencies] +log = "0.4.5" relative-path = "0.4.0" rayon = "1.0.2" fst = "0.3.1" diff --git a/crates/ra_analysis/src/db/mod.rs b/crates/ra_analysis/src/db/mod.rs index 8387118ad5..1a9023697d 100644 --- a/crates/ra_analysis/src/db/mod.rs +++ b/crates/ra_analysis/src/db/mod.rs @@ -1,7 +1,6 @@ pub(crate) mod input; use std::{ - fmt, sync::Arc, }; @@ -17,17 +16,11 @@ use crate::{ FileId, }; -#[derive(Default)] +#[derive(Default, Debug)] pub(crate) struct RootDatabase { runtime: salsa::Runtime, } -impl fmt::Debug for RootDatabase { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.write_str("RootDatabase { ... }") - } -} - impl salsa::Database for RootDatabase { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 97ed55465d..6c1a4749ab 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -98,6 +98,8 @@ impl AnalysisHostImpl { } } pub fn apply_change(&mut self, change: AnalysisChange) { + log::info!("apply_change {:?}", change); + for (file_id, text) in change.files_changed { self.db .query(db::input::FileTextQuery) diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 4a1ae3b647..703938cf9e 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -13,7 +13,7 @@ mod symbol_index; mod completion; use std::{ - fmt::Debug, + fmt, sync::Arc, collections::BTreeMap, }; @@ -60,12 +60,12 @@ pub struct CrateGraph { pub crate_roots: BTreeMap, } -pub trait FileResolver: Debug + Send + Sync + 'static { +pub trait FileResolver: fmt::Debug + Send + Sync + 'static { fn file_stem(&self, file_id: FileId) -> String; fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option; } -#[derive(Debug, Default)] +#[derive(Default)] pub struct AnalysisChange { files_added: Vec<(FileId, String)>, files_changed: Vec<(FileId, String)>, @@ -75,6 +75,19 @@ pub struct AnalysisChange { file_resolver: Option, } +impl fmt::Debug for AnalysisChange { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("AnalysisChange") + .field("files_added", &self.files_added.len()) + .field("files_changed", &self.files_changed.len()) + .field("files_removed", &self.files_removed.len()) + .field("libraries_added", &self.libraries_added.len()) + .field("crate_graph", &self.crate_graph) + .field("file_resolver", &self.file_resolver) + .finish() + } +} + impl AnalysisChange { pub fn new() -> AnalysisChange { diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index e681062ca0..9ddc3fd0bb 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -8,7 +8,7 @@ use gen_lsp_server::{ handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, }; use languageserver_types::NumberOrString; -use ra_analysis::{FileId, LibraryData}; +use ra_analysis::{Canceled, FileId, LibraryData}; use rayon::{self, ThreadPool}; use rustc_hash::FxHashSet; use serde::{de::DeserializeOwned, Serialize}; @@ -376,7 +376,7 @@ impl<'a> PoolDispatcher<'a> { Err(e) => { match e.downcast::() { Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message), - Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) + Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, format!("{}\n{}", e, e.backtrace())) } } }; @@ -408,14 +408,22 @@ fn update_file_notifications_on_threadpool( pool.spawn(move || { for file_id in subscriptions { match handlers::publish_diagnostics(&world, file_id) { - Err(e) => error!("failed to compute diagnostics: {:?}", e), + Err(e) => { + if !is_canceled(&e) { + error!("failed to compute diagnostics: {:?}", e); + } + }, Ok(params) => { let not = RawNotification::new::(¶ms); sender.send(Task::Notify(not)); } } match handlers::publish_decorations(&world, file_id) { - Err(e) => error!("failed to compute decorations: {:?}", e), + Err(e) => { + if !is_canceled(&e) { + error!("failed to compute decorations: {:?}", e); + } + }, Ok(params) => { let not = RawNotification::new::(¶ms); sender.send(Task::Notify(not)) @@ -432,3 +440,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender) { let not = RawNotification::new::(&msg.to_string()); sender.send(RawMessage::Notification(not)); } + +fn is_canceled(e: &failure::Error) -> bool { + e.downcast_ref::().is_some() +}