diff options
author | kjeremy <[email protected]> | 2020-07-13 22:41:47 +0100 |
---|---|---|
committer | kjeremy <[email protected]> | 2020-07-13 22:41:47 +0100 |
commit | aa598ecb75331068f4cacd443512991bc48937dc (patch) | |
tree | 785b88b46016507ed2ced5befce6885780664ff2 /crates/ra_assists/src/lib.rs | |
parent | 853440775d72974585ca3fe39f9688a4d4302dd3 (diff) |
Filter assists
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r-- | crates/ra_assists/src/lib.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 3d61fbded..13a283760 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -37,6 +37,25 @@ pub enum AssistKind { | |||
37 | RefactorRewrite, | 37 | RefactorRewrite, |
38 | } | 38 | } |
39 | 39 | ||
40 | impl AssistKind { | ||
41 | pub fn contains(self, other: AssistKind) -> bool { | ||
42 | if self == other { | ||
43 | return true; | ||
44 | } | ||
45 | |||
46 | match self { | ||
47 | AssistKind::None | AssistKind::Generate => return true, | ||
48 | AssistKind::Refactor => match other { | ||
49 | AssistKind::RefactorExtract | ||
50 | | AssistKind::RefactorInline | ||
51 | | AssistKind::RefactorRewrite => return true, | ||
52 | _ => return false, | ||
53 | }, | ||
54 | _ => return false, | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | |||
40 | /// Unique identifier of the assist, should not be shown to the user | 59 | /// Unique identifier of the assist, should not be shown to the user |
41 | /// directly. | 60 | /// directly. |
42 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 61 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
@@ -67,9 +86,14 @@ impl Assist { | |||
67 | /// | 86 | /// |
68 | /// Assists are returned in the "unresolved" state, that is only labels are | 87 | /// Assists are returned in the "unresolved" state, that is only labels are |
69 | /// returned, without actual edits. | 88 | /// returned, without actual edits. |
70 | pub fn unresolved(db: &RootDatabase, config: &AssistConfig, range: FileRange) -> Vec<Assist> { | 89 | pub fn unresolved( |
90 | db: &RootDatabase, | ||
91 | config: &AssistConfig, | ||
92 | range: FileRange, | ||
93 | allowed: Option<Vec<AssistKind>>, | ||
94 | ) -> Vec<Assist> { | ||
71 | let sema = Semantics::new(db); | 95 | let sema = Semantics::new(db); |
72 | let ctx = AssistContext::new(sema, config, range); | 96 | let ctx = AssistContext::new(sema, config, range, allowed); |
73 | let mut acc = Assists::new_unresolved(&ctx); | 97 | let mut acc = Assists::new_unresolved(&ctx); |
74 | handlers::all().iter().for_each(|handler| { | 98 | handlers::all().iter().for_each(|handler| { |
75 | handler(&mut acc, &ctx); | 99 | handler(&mut acc, &ctx); |
@@ -85,9 +109,10 @@ impl Assist { | |||
85 | db: &RootDatabase, | 109 | db: &RootDatabase, |
86 | config: &AssistConfig, | 110 | config: &AssistConfig, |
87 | range: FileRange, | 111 | range: FileRange, |
112 | allowed: Option<Vec<AssistKind>>, | ||
88 | ) -> Vec<ResolvedAssist> { | 113 | ) -> Vec<ResolvedAssist> { |
89 | let sema = Semantics::new(db); | 114 | let sema = Semantics::new(db); |
90 | let ctx = AssistContext::new(sema, config, range); | 115 | let ctx = AssistContext::new(sema, config, range, allowed); |
91 | let mut acc = Assists::new_resolved(&ctx); | 116 | let mut acc = Assists::new_resolved(&ctx); |
92 | handlers::all().iter().for_each(|handler| { | 117 | handlers::all().iter().for_each(|handler| { |
93 | handler(&mut acc, &ctx); | 118 | handler(&mut acc, &ctx); |