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

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()
}