Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/assists.rs')
| -rw-r--r-- | crates/ide-db/src/assists.rs | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/crates/ide-db/src/assists.rs b/crates/ide-db/src/assists.rs index 1c40685ebb..90ae4a3b5b 100644 --- a/crates/ide-db/src/assists.rs +++ b/crates/ide-db/src/assists.rs @@ -43,9 +43,6 @@ pub enum Command { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AssistKind { - // FIXME: does the None variant make sense? Probably not. - None, - QuickFix, Generate, Refactor, @@ -61,7 +58,7 @@ impl AssistKind { } match self { - AssistKind::None | AssistKind::Generate => true, + AssistKind::Generate => true, AssistKind::Refactor => matches!( other, AssistKind::RefactorExtract @@ -74,7 +71,6 @@ impl AssistKind { pub fn name(&self) -> &str { match self { - AssistKind::None => "None", AssistKind::QuickFix => "QuickFix", AssistKind::Generate => "Generate", AssistKind::Refactor => "Refactor", @@ -90,7 +86,6 @@ impl FromStr for AssistKind { fn from_str(s: &str) -> Result<Self, Self::Err> { match s { - "None" => Ok(AssistKind::None), "QuickFix" => Ok(AssistKind::QuickFix), "Generate" => Ok(AssistKind::Generate), "Refactor" => Ok(AssistKind::Refactor), @@ -105,7 +100,33 @@ 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>); + +impl AssistId { + pub fn quick_fix(id: &'static str) -> AssistId { + AssistId(id, AssistKind::QuickFix, None) + } + + pub fn generate(id: &'static str) -> AssistId { + AssistId(id, AssistKind::Generate, None) + } + + pub fn refactor(id: &'static str) -> AssistId { + AssistId(id, AssistKind::Refactor, None) + } + + pub fn refactor_extract(id: &'static str) -> AssistId { + AssistId(id, AssistKind::RefactorExtract, None) + } + + pub fn refactor_inline(id: &'static str) -> AssistId { + AssistId(id, AssistKind::RefactorInline, None) + } + + pub fn refactor_rewrite(id: &'static str) -> AssistId { + AssistId(id, AssistKind::RefactorRewrite, None) + } +} /// 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 +149,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 +159,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 } } } |