Skip to content

Commit 59c77ff

Browse files
bors[bot]matklad
andauthored
Merge #5866
5866: Improve logging r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents ed51f5b + 3a72afe commit 59c77ff

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

crates/project_model/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod sysroot;
66
mod cfg_flag;
77

88
use std::{
9+
fmt,
910
fs::{self, read_dir, ReadDir},
1011
io,
1112
process::Command,
@@ -27,14 +28,27 @@ pub use crate::{
2728

2829
pub use proc_macro_api::ProcMacroClient;
2930

30-
#[derive(Debug, Clone, Eq, PartialEq)]
31+
#[derive(Clone, Eq, PartialEq)]
3132
pub enum ProjectWorkspace {
3233
/// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
3334
Cargo { cargo: CargoWorkspace, sysroot: Sysroot },
3435
/// Project workspace was manually specified using a `rust-project.json` file.
3536
Json { project: ProjectJson },
3637
}
3738

39+
impl fmt::Debug for ProjectWorkspace {
40+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41+
match self {
42+
ProjectWorkspace::Cargo { cargo, .. } => {
43+
f.debug_struct("Cargo").field("n_packages", &cargo.packages().len()).finish()
44+
}
45+
ProjectWorkspace::Json { project } => {
46+
f.debug_struct("Json").field("n_crates", &project.crates.len()).finish()
47+
}
48+
}
49+
}
50+
}
51+
3852
/// `PackageRoot` describes a package root folder.
3953
/// Which may be an external dependency, or a member of
4054
/// the current workspace.

crates/rust-analyzer/src/bin/main.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ fn setup_logging() -> Result<()> {
6060
}
6161

6262
fn run_server() -> Result<()> {
63-
log::info!("lifecycle: server started");
63+
log::info!("server will start");
6464

6565
let (connection, io_threads) = Connection::stdio();
6666

6767
let (initialize_id, initialize_params) = connection.initialize_start()?;
68+
log::info!("InitializeParams: {}", initialize_params);
6869
let initialize_params =
6970
from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?;
7071

@@ -118,19 +119,17 @@ fn run_server() -> Result<()> {
118119
.filter(|workspaces| !workspaces.is_empty())
119120
.unwrap_or_else(|| vec![config.root_path.clone()]);
120121

121-
config.linked_projects = ProjectManifest::discover_all(&workspace_roots)
122-
.into_iter()
123-
.map(LinkedProject::from)
124-
.collect();
122+
let discovered = ProjectManifest::discover_all(&workspace_roots);
123+
log::info!("discovered projects: {:?}", discovered);
124+
config.linked_projects = discovered.into_iter().map(LinkedProject::from).collect();
125125
}
126126

127127
config
128128
};
129129

130130
rust_analyzer::main_loop(config, connection)?;
131131

132-
log::info!("shutting down IO...");
133132
io_threads.join()?;
134-
log::info!("... IO is down");
133+
log::info!("server did shut down");
135134
Ok(())
136135
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crossbeam_channel::{select, Receiver};
1010
use ide::{Canceled, FileId};
1111
use lsp_server::{Connection, Notification, Request, Response};
1212
use lsp_types::notification::Notification as _;
13+
use project_model::ProjectWorkspace;
14+
use vfs::ChangeKind;
1315

1416
use crate::{
1517
config::Config,
@@ -21,8 +23,6 @@ use crate::{
2123
lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress},
2224
Result,
2325
};
24-
use project_model::ProjectWorkspace;
25-
use vfs::ChangeKind;
2626

2727
pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
2828
log::info!("initial config: {:#?}", config);
@@ -175,9 +175,9 @@ impl GlobalState {
175175
let _p = profile::span("GlobalState::handle_event");
176176

177177
log::info!("handle_event({:?})", event);
178-
let queue_count = self.task_pool.handle.len();
179-
if queue_count > 0 {
180-
log::info!("queued count = {}", queue_count);
178+
let task_queue_len = self.task_pool.handle.len();
179+
if task_queue_len > 0 {
180+
log::info!("task queue len: {}", task_queue_len);
181181
}
182182

183183
let prev_status = self.status;

crates/rust-analyzer/src/reload.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl GlobalState {
9292
}
9393
}
9494
pub(crate) fn fetch_workspaces(&mut self) {
95+
log::info!("will fetch workspaces");
9596
self.task_pool.handle.spawn({
9697
let linked_projects = self.config.linked_projects.clone();
9798
let cargo_config = self.config.cargo.clone();
@@ -112,13 +113,14 @@ impl GlobalState {
112113
}
113114
})
114115
.collect::<Vec<_>>();
116+
log::info!("did fetch workspaces {:?}", workspaces);
115117
Task::Workspaces(workspaces)
116118
}
117119
});
118120
}
119121
pub(crate) fn switch_workspaces(&mut self, workspaces: Vec<anyhow::Result<ProjectWorkspace>>) {
120122
let _p = profile::span("GlobalState::switch_workspaces");
121-
log::info!("reloading projects: {:?}", self.config.linked_projects);
123+
log::info!("will switch workspaces: {:?}", workspaces);
122124

123125
let mut has_errors = false;
124126
let workspaces = workspaces
@@ -223,6 +225,7 @@ impl GlobalState {
223225
self.analysis_host.apply_change(change);
224226
self.process_changes();
225227
self.reload_flycheck();
228+
log::info!("did switch workspaces");
226229
}
227230

228231
fn reload_flycheck(&mut self) {

docs/user/manual.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ Relative paths are interpreted relative to `rust-project.json` file location or
341341

342342
See https://github.com/rust-analyzer/rust-project.json-example for a small example.
343343

344+
You can set `RA_LOG` environmental variable to `"'rust_analyzer=info"` to inspect how rust-analyzer handles config and project loading.
345+
344346
== Features
345347

346348
include::./generated_features.adoc[]

0 commit comments

Comments
 (0)