mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
fix: Fix progress reporting getting stuck
This commit is contained in:
parent
2b02df27c5
commit
0bdbf497b6
6 changed files with 66 additions and 32 deletions
|
@ -497,7 +497,7 @@ fn render_notable_trait_comment(
|
||||||
let mut needs_impl_header = true;
|
let mut needs_impl_header = true;
|
||||||
for (trait_, assoc_types) in notable_traits {
|
for (trait_, assoc_types) in notable_traits {
|
||||||
desc.push_str(if mem::take(&mut needs_impl_header) {
|
desc.push_str(if mem::take(&mut needs_impl_header) {
|
||||||
" // notable traits implemented: "
|
" // Implements notable traits: "
|
||||||
} else {
|
} else {
|
||||||
", "
|
", "
|
||||||
});
|
});
|
||||||
|
@ -530,6 +530,7 @@ fn type_info(
|
||||||
if let Some(res) = closure_ty(sema, config, &ty) {
|
if let Some(res) = closure_ty(sema, config, &ty) {
|
||||||
return Some(res);
|
return Some(res);
|
||||||
};
|
};
|
||||||
|
let db = sema.db;
|
||||||
let TypeInfo { original, adjusted } = ty;
|
let TypeInfo { original, adjusted } = ty;
|
||||||
let mut res = HoverResult::default();
|
let mut res = HoverResult::default();
|
||||||
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
||||||
|
@ -538,29 +539,64 @@ fn type_info(
|
||||||
targets.push(item);
|
targets.push(item);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
walk_and_push_ty(sema.db, &original, &mut push_new_def);
|
walk_and_push_ty(db, &original, &mut push_new_def);
|
||||||
let mut desc = match render_notable_trait_comment(sema.db, ¬able_traits(sema.db, &original))
|
|
||||||
{
|
res.markup = if let Some(adjusted_ty) = adjusted {
|
||||||
Some(desc) => desc + "\n",
|
walk_and_push_ty(db, &adjusted_ty, &mut push_new_def);
|
||||||
None => String::new(),
|
|
||||||
};
|
let notable = {
|
||||||
desc += &if let Some(adjusted_ty) = adjusted {
|
let mut desc = String::new();
|
||||||
walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
|
let mut needs_impl_header = true;
|
||||||
let original = original.display(sema.db).to_string();
|
for (trait_, assoc_types) in notable_traits(db, &original) {
|
||||||
let adjusted = adjusted_ty.display(sema.db).to_string();
|
desc.push_str(if mem::take(&mut needs_impl_header) {
|
||||||
|
"Implements Notable Traits: "
|
||||||
|
} else {
|
||||||
|
", "
|
||||||
|
});
|
||||||
|
format_to!(desc, "{}", trait_.name(db).display(db),);
|
||||||
|
if !assoc_types.is_empty() {
|
||||||
|
desc.push('<');
|
||||||
|
format_to!(
|
||||||
|
desc,
|
||||||
|
"{}",
|
||||||
|
assoc_types.into_iter().format_with(", ", |(ty, name), f| {
|
||||||
|
f(&name.display(db))?;
|
||||||
|
f(&" = ")?;
|
||||||
|
match ty {
|
||||||
|
Some(ty) => f(&ty.display(db)),
|
||||||
|
None => f(&"?"),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
desc.push('>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !desc.is_empty() {
|
||||||
|
desc.push('\n');
|
||||||
|
}
|
||||||
|
desc
|
||||||
|
};
|
||||||
|
|
||||||
|
let original = original.display(db).to_string();
|
||||||
|
let adjusted = adjusted_ty.display(db).to_string();
|
||||||
let static_text_diff_len = "Coerced to: ".len() - "Type: ".len();
|
let static_text_diff_len = "Coerced to: ".len() - "Type: ".len();
|
||||||
format!(
|
format!(
|
||||||
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
|
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n{notable}```\n",
|
||||||
original,
|
original,
|
||||||
adjusted,
|
adjusted,
|
||||||
apad = static_text_diff_len + adjusted.len().max(original.len()),
|
apad = static_text_diff_len + adjusted.len().max(original.len()),
|
||||||
opad = original.len(),
|
opad = original.len(),
|
||||||
)
|
)
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
Markup::fenced_block(&original.display(sema.db)).into()
|
let mut desc = match render_notable_trait_comment(db, ¬able_traits(db, &original)) {
|
||||||
|
Some(desc) => desc + "\n",
|
||||||
|
None => String::new(),
|
||||||
|
};
|
||||||
|
format_to!(desc, "{}", original.display(db));
|
||||||
|
Markup::fenced_block(&desc)
|
||||||
};
|
};
|
||||||
res.markup = desc.into();
|
if let Some(actions) = HoverAction::goto_type_from_targets(db, targets) {
|
||||||
if let Some(actions) = HoverAction::goto_type_from_targets(sema.db, targets) {
|
|
||||||
res.actions.push(actions);
|
res.actions.push(actions);
|
||||||
}
|
}
|
||||||
Some(res)
|
Some(res)
|
||||||
|
|
|
@ -7094,7 +7094,7 @@ fn main(notable$0: u32) {}
|
||||||
*notable*
|
*notable*
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// notable traits implemented: Notable<Assoc = &str, Assoc2 = char>
|
// Implements notable traits: Notable<Assoc = &str, Assoc2 = char>
|
||||||
// size = 4, align = 4
|
// size = 4, align = 4
|
||||||
notable: u32
|
notable: u32
|
||||||
```
|
```
|
||||||
|
@ -7126,7 +7126,7 @@ impl Iterator for S {
|
||||||
```
|
```
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// notable traits implemented: Notable, Future<Output = u32>, Iterator<Item = S>
|
// Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S>
|
||||||
// size = 0, align = 1
|
// size = 0, align = 1
|
||||||
struct S
|
struct S
|
||||||
```
|
```
|
||||||
|
@ -7154,8 +7154,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
// notable traits implemented: Notable, Future<Output = u32>, Iterator<Item = S>
|
|
||||||
```rust
|
```rust
|
||||||
|
// Implements notable traits: Notable, Future<Output = u32>, Iterator<Item = S>
|
||||||
S
|
S
|
||||||
```"#]],
|
```"#]],
|
||||||
);
|
);
|
||||||
|
|
|
@ -318,7 +318,7 @@ fn load_crate_graph(
|
||||||
for task in receiver {
|
for task in receiver {
|
||||||
match task {
|
match task {
|
||||||
vfs::loader::Message::Progress { n_done, n_total, .. } => {
|
vfs::loader::Message::Progress { n_done, n_total, .. } => {
|
||||||
if n_done == n_total {
|
if n_done == Some(n_total) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,19 +589,17 @@ impl GlobalState {
|
||||||
vfs::loader::Message::Progress { n_total, n_done, dir, config_version } => {
|
vfs::loader::Message::Progress { n_total, n_done, dir, config_version } => {
|
||||||
always!(config_version <= self.vfs_config_version);
|
always!(config_version <= self.vfs_config_version);
|
||||||
|
|
||||||
|
let state = match n_done {
|
||||||
|
None => Progress::Begin,
|
||||||
|
Some(done) if done == n_total => Progress::End,
|
||||||
|
Some(_) => Progress::Report,
|
||||||
|
};
|
||||||
|
let n_done = n_done.unwrap_or_default();
|
||||||
|
|
||||||
self.vfs_progress_config_version = config_version;
|
self.vfs_progress_config_version = config_version;
|
||||||
self.vfs_progress_n_total = n_total;
|
self.vfs_progress_n_total = n_total;
|
||||||
self.vfs_progress_n_done = n_done;
|
self.vfs_progress_n_done = n_done;
|
||||||
|
|
||||||
let state = if n_done == 0 {
|
|
||||||
Progress::Begin
|
|
||||||
} else if n_done < n_total {
|
|
||||||
Progress::Report
|
|
||||||
} else {
|
|
||||||
assert_eq!(n_done, n_total);
|
|
||||||
Progress::End
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut message = format!("{n_done}/{n_total}");
|
let mut message = format!("{n_done}/{n_total}");
|
||||||
if let Some(dir) = dir {
|
if let Some(dir) = dir {
|
||||||
message += &format!(
|
message += &format!(
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl NotifyActor {
|
||||||
let n_total = config.load.len();
|
let n_total = config.load.len();
|
||||||
self.send(loader::Message::Progress {
|
self.send(loader::Message::Progress {
|
||||||
n_total,
|
n_total,
|
||||||
n_done: 0,
|
n_done: None,
|
||||||
config_version,
|
config_version,
|
||||||
dir: None,
|
dir: None,
|
||||||
});
|
});
|
||||||
|
@ -120,14 +120,14 @@ impl NotifyActor {
|
||||||
let files =
|
let files =
|
||||||
self.load_entry(entry, watch, |file| loader::Message::Progress {
|
self.load_entry(entry, watch, |file| loader::Message::Progress {
|
||||||
n_total,
|
n_total,
|
||||||
n_done: i,
|
n_done: Some(i),
|
||||||
dir: Some(file),
|
dir: Some(file),
|
||||||
config_version,
|
config_version,
|
||||||
});
|
});
|
||||||
self.send(loader::Message::Loaded { files });
|
self.send(loader::Message::Loaded { files });
|
||||||
self.send(loader::Message::Progress {
|
self.send(loader::Message::Progress {
|
||||||
n_total,
|
n_total,
|
||||||
n_done: i + 1,
|
n_done: Some(i + 1),
|
||||||
config_version,
|
config_version,
|
||||||
dir: None,
|
dir: None,
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub enum Message {
|
||||||
/// The total files to be loaded.
|
/// The total files to be loaded.
|
||||||
n_total: usize,
|
n_total: usize,
|
||||||
/// The files that have been loaded successfully.
|
/// The files that have been loaded successfully.
|
||||||
n_done: usize,
|
n_done: Option<usize>,
|
||||||
/// The dir being loaded, `None` if its for a file.
|
/// The dir being loaded, `None` if its for a file.
|
||||||
dir: Option<AbsPathBuf>,
|
dir: Option<AbsPathBuf>,
|
||||||
/// The [`Config`] version.
|
/// The [`Config`] version.
|
||||||
|
|
Loading…
Reference in a new issue