Skip to content

Commit c9afd41

Browse files
committed
Auto merge of rust-lang#15636 - 9999years:show-which-roots-are-scanned, r=Veykril
Show which roots are being scanned in progress messages This changes the `Roots Scanned` message to include the directory being scanned. Before: `Roots Scanned 206/210 (98%)` After: `Roots Scanned 206/210: .direnv (98%)` This makes it a lot easier to tell that `rust-analyzer` isn't crashed, it's just trying to scan a huge directory. See: rust-lang#12613
2 parents 87e609a + 3981508 commit c9afd41

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

crates/load-cargo/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn load_crate_graph(
317317
// wait until Vfs has loaded all roots
318318
for task in receiver {
319319
match task {
320-
vfs::loader::Message::Progress { n_done, n_total, config_version: _ } => {
320+
vfs::loader::Message::Progress { n_done, n_total, .. } => {
321321
if n_done == n_total {
322322
break;
323323
}

crates/rust-analyzer/src/main_loop.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl GlobalState {
586586
}
587587
}
588588
}
589-
vfs::loader::Message::Progress { n_total, n_done, config_version } => {
589+
vfs::loader::Message::Progress { n_total, n_done, dir, config_version } => {
590590
always!(config_version <= self.vfs_config_version);
591591

592592
self.vfs_progress_config_version = config_version;
@@ -601,10 +601,23 @@ impl GlobalState {
601601
assert_eq!(n_done, n_total);
602602
Progress::End
603603
};
604+
605+
let mut message = format!("{n_done}/{n_total}");
606+
if let Some(dir) = dir {
607+
message += &format!(
608+
": {}",
609+
match dir.strip_prefix(&self.config.root_path()) {
610+
Some(relative_path) => relative_path.as_ref(),
611+
None => dir.as_ref(),
612+
}
613+
.display()
614+
);
615+
}
616+
604617
self.report_progress(
605618
"Roots Scanned",
606619
state,
607-
Some(format!("{n_done}/{n_total}")),
620+
Some(message),
608621
Some(Progress::fraction(n_done, n_total)),
609622
None,
610623
);

crates/vfs-notify/src/lib.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ impl NotifyActor {
103103
let config_version = config.version;
104104

105105
let n_total = config.load.len();
106-
self.send(loader::Message::Progress { n_total, n_done: 0, config_version });
106+
self.send(loader::Message::Progress {
107+
n_total,
108+
n_done: 0,
109+
config_version,
110+
dir: None,
111+
});
107112

108113
self.watched_entries.clear();
109114

@@ -112,12 +117,19 @@ impl NotifyActor {
112117
if watch {
113118
self.watched_entries.push(entry.clone());
114119
}
115-
let files = self.load_entry(entry, watch);
120+
let files =
121+
self.load_entry(entry, watch, |file| loader::Message::Progress {
122+
n_total,
123+
n_done: i,
124+
dir: Some(file),
125+
config_version,
126+
});
116127
self.send(loader::Message::Loaded { files });
117128
self.send(loader::Message::Progress {
118129
n_total,
119130
n_done: i + 1,
120131
config_version,
132+
dir: None,
121133
});
122134
}
123135
}
@@ -170,6 +182,7 @@ impl NotifyActor {
170182
&mut self,
171183
entry: loader::Entry,
172184
watch: bool,
185+
make_message: impl Fn(AbsPathBuf) -> loader::Message,
173186
) -> Vec<(AbsPathBuf, Option<Vec<u8>>)> {
174187
match entry {
175188
loader::Entry::Files(files) => files
@@ -186,6 +199,7 @@ impl NotifyActor {
186199
let mut res = Vec::new();
187200

188201
for root in &dirs.include {
202+
self.send(make_message(root.clone()));
189203
let walkdir =
190204
WalkDir::new(root).follow_links(true).into_iter().filter_entry(|entry| {
191205
if !entry.file_type().is_dir() {
@@ -197,9 +211,13 @@ impl NotifyActor {
197211
});
198212

199213
let files = walkdir.filter_map(|it| it.ok()).filter_map(|entry| {
214+
let depth = entry.depth();
200215
let is_dir = entry.file_type().is_dir();
201216
let is_file = entry.file_type().is_file();
202217
let abs_path = AbsPathBuf::assert(entry.into_path());
218+
if depth < 2 && is_dir {
219+
self.send(make_message(abs_path.clone()));
220+
}
203221
if is_dir && watch {
204222
self.watch(abs_path.clone());
205223
}

crates/vfs/src/loader.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ pub enum Message {
4848
/// Indicate a gradual progress.
4949
///
5050
/// This is supposed to be the number of loaded files.
51-
Progress { n_total: usize, n_done: usize, config_version: u32 },
51+
Progress {
52+
/// The total files to be loaded.
53+
n_total: usize,
54+
/// The files that have been loaded successfully.
55+
n_done: usize,
56+
/// The dir being loaded, `None` if its for a file.
57+
dir: Option<AbsPathBuf>,
58+
/// The [`Config`] version.
59+
config_version: u32,
60+
},
5261
/// The handle loaded the following files' content.
5362
Loaded { files: Vec<(AbsPathBuf, Option<Vec<u8>>)> },
5463
/// The handle loaded the following files' content.
@@ -204,10 +213,11 @@ impl fmt::Debug for Message {
204213
Message::Changed { files } => {
205214
f.debug_struct("Changed").field("n_files", &files.len()).finish()
206215
}
207-
Message::Progress { n_total, n_done, config_version } => f
216+
Message::Progress { n_total, n_done, dir, config_version } => f
208217
.debug_struct("Progress")
209218
.field("n_total", n_total)
210219
.field("n_done", n_done)
220+
.field("dir", dir)
211221
.field("config_version", config_version)
212222
.finish(),
213223
}

0 commit comments

Comments
 (0)