Improve logging

This commit is contained in:
Aleksey Kladov 2018-10-25 16:03:49 +03:00
parent ee4d904cfb
commit 56df0fc83c
6 changed files with 41 additions and 18 deletions

8
Cargo.lock generated
View file

@ -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"

View file

@ -5,6 +5,7 @@ version = "0.1.0"
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
log = "0.4.5"
relative-path = "0.4.0"
rayon = "1.0.2"
fst = "0.3.1"

View file

@ -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<RootDatabase>,
}
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<RootDatabase> {
&self.runtime

View file

@ -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)

View file

@ -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<CrateId, FileId>,
}
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<FileId>;
}
#[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<FileResolverImp>,
}
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 {

View file

@ -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::<LspError>() {
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::<req::PublishDiagnostics>(&params);
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::<req::PublishDecorations>(&params);
sender.send(Task::Notify(not))
@ -432,3 +440,7 @@ fn feedback(intrnal_mode: bool, msg: &str, sender: &Sender<RawMessage>) {
let not = RawNotification::new::<req::InternalFeedback>(&msg.to_string());
sender.send(RawMessage::Notification(not));
}
fn is_canceled(e: &failure::Error) -> bool {
e.downcast_ref::<Canceled>().is_some()
}