Speed up resolving "Generate delegate method" assist (part 1)

Fix #19322

Sometimes there are 185 "Generate delegate" assists with the same
assist_id and asssist_kind.  This commit introduces and additional
differentiator: assist_subtype.  Therefore, when the LSP client sends
an assist resolve request, rust-analyzer only need to compute edits
for a single assist instead of 185.
This commit is contained in:
Felicián Németh 2025-03-15 08:14:20 +01:00
parent dab1329f35
commit 7aa70a86d1
5 changed files with 30 additions and 10 deletions

View file

@ -105,7 +105,7 @@ impl FromStr for AssistKind {
/// Unique identifier of the assist, should not be shown to the user
/// directly.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AssistId(pub &'static str, pub AssistKind);
pub struct AssistId(pub &'static str, pub AssistKind, pub Option<usize>);
/// A way to control how many assist to resolve during the assist resolution.
/// When an assist is resolved, its edits are calculated that might be costly to always do by default.
@ -128,6 +128,8 @@ pub struct SingleResolve {
pub assist_id: String,
// The kind of the assist.
pub assist_kind: AssistKind,
/// Subtype of the assist. When many assists have the same id, it differentiates among them.
pub assist_subtype: Option<usize>,
}
impl AssistResolveStrategy {
@ -136,7 +138,9 @@ impl AssistResolveStrategy {
AssistResolveStrategy::None => false,
AssistResolveStrategy::All => true,
AssistResolveStrategy::Single(single_resolve) => {
single_resolve.assist_id == id.0 && single_resolve.assist_kind == id.1
single_resolve.assist_id == id.0
&& single_resolve.assist_kind == id.1
&& single_resolve.assist_subtype == id.2
}
}
}