Skip to content

Commit 5b62ebc

Browse files
committed
Auto merge of rust-lang#16383 - Veykril:progress, r=Veykril
fix: Fix progress reporting getting stuck Fixes rust-lang/rust-analyzer#16382
2 parents c820980 + 0bdbf49 commit 5b62ebc

File tree

6 files changed

+66
-32
lines changed

6 files changed

+66
-32
lines changed

crates/ide/src/hover/render.rs

+51-15
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ fn render_notable_trait_comment(
497497
let mut needs_impl_header = true;
498498
for (trait_, assoc_types) in notable_traits {
499499
desc.push_str(if mem::take(&mut needs_impl_header) {
500-
" // notable traits implemented: "
500+
" // Implements notable traits: "
501501
} else {
502502
", "
503503
});
@@ -530,6 +530,7 @@ fn type_info(
530530
if let Some(res) = closure_ty(sema, config, &ty) {
531531
return Some(res);
532532
};
533+
let db = sema.db;
533534
let TypeInfo { original, adjusted } = ty;
534535
let mut res = HoverResult::default();
535536
let mut targets: Vec<hir::ModuleDef> = Vec::new();
@@ -538,29 +539,64 @@ fn type_info(
538539
targets.push(item);
539540
}
540541
};
541-
walk_and_push_ty(sema.db, &original, &mut push_new_def);
542-
let mut desc = match render_notable_trait_comment(sema.db, &notable_traits(sema.db, &original))
543-
{
544-
Some(desc) => desc + "\n",
545-
None => String::new(),
546-
};
547-
desc += &if let Some(adjusted_ty) = adjusted {
548-
walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
549-
let original = original.display(sema.db).to_string();
550-
let adjusted = adjusted_ty.display(sema.db).to_string();
542+
walk_and_push_ty(db, &original, &mut push_new_def);
543+
544+
res.markup = if let Some(adjusted_ty) = adjusted {
545+
walk_and_push_ty(db, &adjusted_ty, &mut push_new_def);
546+
547+
let notable = {
548+
let mut desc = String::new();
549+
let mut needs_impl_header = true;
550+
for (trait_, assoc_types) in notable_traits(db, &original) {
551+
desc.push_str(if mem::take(&mut needs_impl_header) {
552+
"Implements Notable Traits: "
553+
} else {
554+
", "
555+
});
556+
format_to!(desc, "{}", trait_.name(db).display(db),);
557+
if !assoc_types.is_empty() {
558+
desc.push('<');
559+
format_to!(
560+
desc,
561+
"{}",
562+
assoc_types.into_iter().format_with(", ", |(ty, name), f| {
563+
f(&name.display(db))?;
564+
f(&" = ")?;
565+
match ty {
566+
Some(ty) => f(&ty.display(db)),
567+
None => f(&"?"),
568+
}
569+
})
570+
);
571+
desc.push('>');
572+
}
573+
}
574+
if !desc.is_empty() {
575+
desc.push('\n');
576+
}
577+
desc
578+
};
579+
580+
let original = original.display(db).to_string();
581+
let adjusted = adjusted_ty.display(db).to_string();
551582
let static_text_diff_len = "Coerced to: ".len() - "Type: ".len();
552583
format!(
553-
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
584+
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n{notable}```\n",
554585
original,
555586
adjusted,
556587
apad = static_text_diff_len + adjusted.len().max(original.len()),
557588
opad = original.len(),
558589
)
590+
.into()
559591
} else {
560-
Markup::fenced_block(&original.display(sema.db)).into()
592+
let mut desc = match render_notable_trait_comment(db, &notable_traits(db, &original)) {
593+
Some(desc) => desc + "\n",
594+
None => String::new(),
595+
};
596+
format_to!(desc, "{}", original.display(db));
597+
Markup::fenced_block(&desc)
561598
};
562-
res.markup = desc.into();
563-
if let Some(actions) = HoverAction::goto_type_from_targets(sema.db, targets) {
599+
if let Some(actions) = HoverAction::goto_type_from_targets(db, targets) {
564600
res.actions.push(actions);
565601
}
566602
Some(res)

crates/ide/src/hover/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7094,7 +7094,7 @@ fn main(notable$0: u32) {}
70947094
*notable*
70957095
70967096
```rust
7097-
// notable traits implemented: Notable<Assoc = &str, Assoc2 = char>
7097+
// Implements notable traits: Notable<Assoc = &str, Assoc2 = char>
70987098
// size = 4, align = 4
70997099
notable: u32
71007100
```
@@ -7126,7 +7126,7 @@ impl Iterator for S {
71267126
```
71277127
71287128
```rust
7129-
// notable traits implemented: Notable, Future<Output = u32>, Iterator<Item = S>
7129+
// Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S>
71307130
// size = 0, align = 1
71317131
struct S
71327132
```
@@ -7154,8 +7154,8 @@ fn main() {
71547154
}
71557155
"#,
71567156
expect![[r#"
7157-
// notable traits implemented: Notable, Future<Output = u32>, Iterator<Item = S>
71587157
```rust
7158+
// Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S>
71597159
S
71607160
```"#]],
71617161
);

crates/load-cargo/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn load_crate_graph(
318318
for task in receiver {
319319
match task {
320320
vfs::loader::Message::Progress { n_done, n_total, .. } => {
321-
if n_done == n_total {
321+
if n_done == Some(n_total) {
322322
break;
323323
}
324324
}

crates/rust-analyzer/src/main_loop.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,17 @@ impl GlobalState {
589589
vfs::loader::Message::Progress { n_total, n_done, dir, config_version } => {
590590
always!(config_version <= self.vfs_config_version);
591591

592+
let state = match n_done {
593+
None => Progress::Begin,
594+
Some(done) if done == n_total => Progress::End,
595+
Some(_) => Progress::Report,
596+
};
597+
let n_done = n_done.unwrap_or_default();
598+
592599
self.vfs_progress_config_version = config_version;
593600
self.vfs_progress_n_total = n_total;
594601
self.vfs_progress_n_done = n_done;
595602

596-
let state = if n_done == 0 {
597-
Progress::Begin
598-
} else if n_done < n_total {
599-
Progress::Report
600-
} else {
601-
assert_eq!(n_done, n_total);
602-
Progress::End
603-
};
604-
605603
let mut message = format!("{n_done}/{n_total}");
606604
if let Some(dir) = dir {
607605
message += &format!(

crates/vfs-notify/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl NotifyActor {
105105
let n_total = config.load.len();
106106
self.send(loader::Message::Progress {
107107
n_total,
108-
n_done: 0,
108+
n_done: None,
109109
config_version,
110110
dir: None,
111111
});
@@ -120,14 +120,14 @@ impl NotifyActor {
120120
let files =
121121
self.load_entry(entry, watch, |file| loader::Message::Progress {
122122
n_total,
123-
n_done: i,
123+
n_done: Some(i),
124124
dir: Some(file),
125125
config_version,
126126
});
127127
self.send(loader::Message::Loaded { files });
128128
self.send(loader::Message::Progress {
129129
n_total,
130-
n_done: i + 1,
130+
n_done: Some(i + 1),
131131
config_version,
132132
dir: None,
133133
});

crates/vfs/src/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub enum Message {
5252
/// The total files to be loaded.
5353
n_total: usize,
5454
/// The files that have been loaded successfully.
55-
n_done: usize,
55+
n_done: Option<usize>,
5656
/// The dir being loaded, `None` if its for a file.
5757
dir: Option<AbsPathBuf>,
5858
/// The [`Config`] version.

0 commit comments

Comments
 (0)