Reapply completion docs prefetch (#22306)
Leaving release notes as N/A because it had release notes in the past in #21705 In #21286, documentation resolution was made more efficient by only resolving the current completion. However, this meant that single line documentation shown inline in the menu was missing until scrolled to. This also meant that it would wait for navigation to resolve completion docs, leading to lag for displaying documentation. This change resolves this by attempting to fetch all the completions that will be shown. It also mostly avoids re-resolving completions. It intentionally re-resolves the current selection on navigation, as some language servers will respond with more information later on. Release Notes: - N/A
This commit is contained in:
parent
8ee04bf04a
commit
c01403b4b1
6 changed files with 308 additions and 195 deletions
|
@ -24,6 +24,7 @@ futures-lite.workspace = true
|
|||
futures.workspace = true
|
||||
git2 = { workspace = true, optional = true }
|
||||
globset.workspace = true
|
||||
itertools.workspace = true
|
||||
log.workspace = true
|
||||
rand = { workspace = true, optional = true }
|
||||
regex.workspace = true
|
||||
|
|
|
@ -8,6 +8,7 @@ pub mod test;
|
|||
|
||||
use futures::Future;
|
||||
|
||||
use itertools::Either;
|
||||
use regex::Regex;
|
||||
use std::sync::{LazyLock, OnceLock};
|
||||
use std::{
|
||||
|
@ -199,6 +200,35 @@ pub fn measure<R>(label: &str, f: impl FnOnce() -> R) -> R {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn iterate_expanded_and_wrapped_usize_range(
|
||||
range: Range<usize>,
|
||||
additional_before: usize,
|
||||
additional_after: usize,
|
||||
wrap_length: usize,
|
||||
) -> impl Iterator<Item = usize> {
|
||||
let start_wraps = range.start < additional_before;
|
||||
let end_wraps = wrap_length < range.end + additional_after;
|
||||
if start_wraps && end_wraps {
|
||||
Either::Left(0..wrap_length)
|
||||
} else if start_wraps {
|
||||
let wrapped_start = (range.start + wrap_length).saturating_sub(additional_before);
|
||||
if wrapped_start <= range.end {
|
||||
Either::Left(0..wrap_length)
|
||||
} else {
|
||||
Either::Right((0..range.end + additional_after).chain(wrapped_start..wrap_length))
|
||||
}
|
||||
} else if end_wraps {
|
||||
let wrapped_end = range.end + additional_after - wrap_length;
|
||||
if range.start <= wrapped_end {
|
||||
Either::Left(0..wrap_length)
|
||||
} else {
|
||||
Either::Right((0..wrapped_end).chain(range.start - additional_before..wrap_length))
|
||||
}
|
||||
} else {
|
||||
Either::Left((range.start - additional_before)..(range.end + additional_after))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ResultExt<E> {
|
||||
type Ok;
|
||||
|
||||
|
@ -734,4 +764,48 @@ Line 2
|
|||
Line 3"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterate_expanded_and_wrapped_usize_range() {
|
||||
// Neither wrap
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(2..4, 1, 1, 8).collect::<Vec<usize>>(),
|
||||
(1..5).collect::<Vec<usize>>()
|
||||
);
|
||||
// Start wraps
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(2..4, 3, 1, 8).collect::<Vec<usize>>(),
|
||||
((0..5).chain(7..8)).collect::<Vec<usize>>()
|
||||
);
|
||||
// Start wraps all the way around
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(2..4, 5, 1, 8).collect::<Vec<usize>>(),
|
||||
(0..8).collect::<Vec<usize>>()
|
||||
);
|
||||
// Start wraps all the way around and past 0
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(2..4, 10, 1, 8).collect::<Vec<usize>>(),
|
||||
(0..8).collect::<Vec<usize>>()
|
||||
);
|
||||
// End wraps
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(3..5, 1, 4, 8).collect::<Vec<usize>>(),
|
||||
(0..1).chain(2..8).collect::<Vec<usize>>()
|
||||
);
|
||||
// End wraps all the way around
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(3..5, 1, 5, 8).collect::<Vec<usize>>(),
|
||||
(0..8).collect::<Vec<usize>>()
|
||||
);
|
||||
// End wraps all the way around and past the end
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(3..5, 1, 10, 8).collect::<Vec<usize>>(),
|
||||
(0..8).collect::<Vec<usize>>()
|
||||
);
|
||||
// Both start and end wrap
|
||||
assert_eq!(
|
||||
iterate_expanded_and_wrapped_usize_range(3..5, 4, 4, 8).collect::<Vec<usize>>(),
|
||||
(0..8).collect::<Vec<usize>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue