From 39dfca23f1634c1e21819806bdd696c8096d0f0f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 23 Oct 2020 17:07:06 +0200 Subject: Add tracing to main rust-analyzer binary --- crates/hir_ty/Cargo.toml | 2 +- crates/rust-analyzer/Cargo.toml | 3 +++ crates/rust-analyzer/src/bin/main.rs | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index be7c812cb..367a1b98d 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml @@ -17,7 +17,7 @@ ena = "0.14.0" log = "0.4.8" rustc-hash = "1.1.0" scoped-tls = "1" -chalk-solve = "0.34" +chalk-solve = { version = "0.34", default-features = false } chalk-ir = "0.34" chalk-recursive = "0.34" diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index 2f0fa9726..975b24aaf 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml @@ -32,6 +32,9 @@ threadpool = "1.7.1" rayon = "1.5" mimalloc = { version = "0.1.19", default-features = false, optional = true } lsp-server = "0.4.0" +tracing = "0.1" +tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } +tracing-tree = { version = "0.1.4" } stdx = { path = "../stdx", version = "0.0.0" } flycheck = { path = "../flycheck", version = "0.0.0" } diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 97b246a32..4175e569e 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -68,10 +68,32 @@ fn setup_logging(log_file: Option) -> Result<()> { let filter = env::var("RA_LOG").ok(); logger::Logger::new(log_file, filter.as_deref()).install(); + tracing_setup::setup_tracing()?; + profile::init(); Ok(()) } +mod tracing_setup { + use tracing::subscriber; + use tracing_subscriber::layer::SubscriberExt; + use tracing_subscriber::EnvFilter; + use tracing_subscriber::Registry; + use tracing_tree::HierarchicalLayer; + + pub fn setup_tracing() -> super::Result<()> { + let filter = EnvFilter::from_env("CHALK_DEBUG"); + let layer = HierarchicalLayer::default() + .with_indent_lines(true) + .with_ansi(false) + .with_indent_amount(2) + .with_writer(std::io::stderr); + let subscriber = Registry::default().with(filter).with(layer); + subscriber::set_global_default(subscriber)?; + Ok(()) + } +} + fn run_server() -> Result<()> { log::info!("server will start"); -- cgit v1.2.3