diff options
author | Kirill Bulatov <[email protected]> | 2021-05-03 16:03:28 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-05-03 16:03:28 +0100 |
commit | 1679a376f30c5ad8971c0f855074a3f489fee5fa (patch) | |
tree | 1ffe5d504426f6e1d9cbf1c56d9e6b91ab9ac43d /crates/ide_assists/src | |
parent | e5cdcb8b124f5b7d59950429787e760e46388f72 (diff) |
Resolve single assist only
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r-- | crates/ide_assists/src/lib.rs | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 397d2a3d0..01addffe9 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs | |||
@@ -17,6 +17,8 @@ mod tests; | |||
17 | pub mod utils; | 17 | pub mod utils; |
18 | pub mod ast_transform; | 18 | pub mod ast_transform; |
19 | 19 | ||
20 | use std::str::FromStr; | ||
21 | |||
20 | use hir::Semantics; | 22 | use hir::Semantics; |
21 | use ide_db::base_db::FileRange; | 23 | use ide_db::base_db::FileRange; |
22 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; | 24 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; |
@@ -56,6 +58,35 @@ impl AssistKind { | |||
56 | _ => return false, | 58 | _ => return false, |
57 | } | 59 | } |
58 | } | 60 | } |
61 | |||
62 | pub fn name(&self) -> &str { | ||
63 | match self { | ||
64 | AssistKind::None => "None", | ||
65 | AssistKind::QuickFix => "QuickFix", | ||
66 | AssistKind::Generate => "Generate", | ||
67 | AssistKind::Refactor => "Refactor", | ||
68 | AssistKind::RefactorExtract => "RefactorExtract", | ||
69 | AssistKind::RefactorInline => "RefactorInline", | ||
70 | AssistKind::RefactorRewrite => "RefactorRewrite", | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | impl FromStr for AssistKind { | ||
76 | type Err = String; | ||
77 | |||
78 | fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
79 | match s { | ||
80 | "None" => Ok(AssistKind::None), | ||
81 | "QuickFix" => Ok(AssistKind::QuickFix), | ||
82 | "Generate" => Ok(AssistKind::Generate), | ||
83 | "Refactor" => Ok(AssistKind::Refactor), | ||
84 | "RefactorExtract" => Ok(AssistKind::RefactorExtract), | ||
85 | "RefactorInline" => Ok(AssistKind::RefactorInline), | ||
86 | "RefactorRewrite" => Ok(AssistKind::RefactorRewrite), | ||
87 | unknown => Err(format!("Unknown AssistKind: '{}'", unknown)), | ||
88 | } | ||
89 | } | ||
59 | } | 90 | } |
60 | 91 | ||
61 | /// Unique identifier of the assist, should not be shown to the user | 92 | /// Unique identifier of the assist, should not be shown to the user |
@@ -64,11 +95,11 @@ impl AssistKind { | |||
64 | pub struct AssistId(pub &'static str, pub AssistKind); | 95 | pub struct AssistId(pub &'static str, pub AssistKind); |
65 | 96 | ||
66 | // TODO kb docs | 97 | // TODO kb docs |
67 | #[derive(Debug, Clone, Copy)] | 98 | #[derive(Debug, Clone)] |
68 | pub enum AssistResolveStrategy { | 99 | pub enum AssistResolveStrategy { |
69 | None, | 100 | None, |
70 | All, | 101 | All, |
71 | Single(AssistId), | 102 | Single(String, AssistKind), |
72 | } | 103 | } |
73 | 104 | ||
74 | impl AssistResolveStrategy { | 105 | impl AssistResolveStrategy { |
@@ -76,7 +107,9 @@ impl AssistResolveStrategy { | |||
76 | match self { | 107 | match self { |
77 | AssistResolveStrategy::None => false, | 108 | AssistResolveStrategy::None => false, |
78 | AssistResolveStrategy::All => true, | 109 | AssistResolveStrategy::All => true, |
79 | AssistResolveStrategy::Single(id_to_resolve) => id_to_resolve == id, | 110 | AssistResolveStrategy::Single(id_to_resolve, kind) => { |
111 | id_to_resolve == id.0 && kind == &id.1 | ||
112 | } | ||
80 | } | 113 | } |
81 | } | 114 | } |
82 | } | 115 | } |