diff options
author | Aleksey Kladov <[email protected]> | 2020-05-07 16:29:23 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-05-07 16:29:23 +0100 |
commit | 28fcff125a73ab2fc4aeaa100fc472af5178db20 (patch) | |
tree | 3021cbb36741e7efd6172561cab5e916a99cdc92 /crates/ra_assists/src/lib.rs | |
parent | c6b81bc013b5278b917d109b723405e0df413323 (diff) |
Nicer API
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r-- | crates/ra_assists/src/lib.rs | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index a91975d8c..b6dc7cb1b 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -29,6 +29,9 @@ pub(crate) use crate::assist_context::{AssistContext, Assists}; | |||
29 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 29 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
30 | pub struct AssistId(pub &'static str); | 30 | pub struct AssistId(pub &'static str); |
31 | 31 | ||
32 | #[derive(Clone, Debug)] | ||
33 | pub struct GroupLabel(pub String); | ||
34 | |||
32 | #[derive(Debug, Clone)] | 35 | #[derive(Debug, Clone)] |
33 | pub struct Assist { | 36 | pub struct Assist { |
34 | pub id: AssistId, | 37 | pub id: AssistId, |
@@ -40,10 +43,41 @@ pub struct Assist { | |||
40 | pub target: TextRange, | 43 | pub target: TextRange, |
41 | } | 44 | } |
42 | 45 | ||
43 | #[derive(Clone, Debug)] | 46 | #[derive(Debug, Clone)] |
44 | pub struct GroupLabel(pub String); | 47 | pub struct ResolvedAssist { |
48 | pub assist: Assist, | ||
49 | pub source_change: SourceChange, | ||
50 | } | ||
45 | 51 | ||
46 | impl Assist { | 52 | impl Assist { |
53 | /// Return all the assists applicable at the given position. | ||
54 | /// | ||
55 | /// Assists are returned in the "unresolved" state, that is only labels are | ||
56 | /// returned, without actual edits. | ||
57 | pub fn unresolved(db: &RootDatabase, range: FileRange) -> Vec<Assist> { | ||
58 | let sema = Semantics::new(db); | ||
59 | let ctx = AssistContext::new(sema, range); | ||
60 | let mut acc = Assists::new_unresolved(&ctx); | ||
61 | handlers::all().iter().for_each(|handler| { | ||
62 | handler(&mut acc, &ctx); | ||
63 | }); | ||
64 | acc.finish_unresolved() | ||
65 | } | ||
66 | |||
67 | /// Return all the assists applicable at the given position. | ||
68 | /// | ||
69 | /// Assists are returned in the "resolved" state, that is with edit fully | ||
70 | /// computed. | ||
71 | pub fn resolved(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> { | ||
72 | let sema = Semantics::new(db); | ||
73 | let ctx = AssistContext::new(sema, range); | ||
74 | let mut acc = Assists::new_resolved(&ctx); | ||
75 | handlers::all().iter().for_each(|handler| { | ||
76 | handler(&mut acc, &ctx); | ||
77 | }); | ||
78 | acc.finish_resolved() | ||
79 | } | ||
80 | |||
47 | pub(crate) fn new( | 81 | pub(crate) fn new( |
48 | id: AssistId, | 82 | id: AssistId, |
49 | label: String, | 83 | label: String, |
@@ -56,40 +90,6 @@ impl Assist { | |||
56 | } | 90 | } |
57 | } | 91 | } |
58 | 92 | ||
59 | #[derive(Debug, Clone)] | ||
60 | pub struct ResolvedAssist { | ||
61 | pub assist: Assist, | ||
62 | pub source_change: SourceChange, | ||
63 | } | ||
64 | |||
65 | /// Return all the assists applicable at the given position. | ||
66 | /// | ||
67 | /// Assists are returned in the "unresolved" state, that is only labels are | ||
68 | /// returned, without actual edits. | ||
69 | pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<Assist> { | ||
70 | let sema = Semantics::new(db); | ||
71 | let ctx = AssistContext::new(sema, range); | ||
72 | let mut acc = Assists::new_unresolved(&ctx); | ||
73 | handlers::all().iter().for_each(|handler| { | ||
74 | handler(&mut acc, &ctx); | ||
75 | }); | ||
76 | acc.finish_unresolved() | ||
77 | } | ||
78 | |||
79 | /// Return all the assists applicable at the given position. | ||
80 | /// | ||
81 | /// Assists are returned in the "resolved" state, that is with edit fully | ||
82 | /// computed. | ||
83 | pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> { | ||
84 | let sema = Semantics::new(db); | ||
85 | let ctx = AssistContext::new(sema, range); | ||
86 | let mut acc = Assists::new_resolved(&ctx); | ||
87 | handlers::all().iter().for_each(|handler| { | ||
88 | handler(&mut acc, &ctx); | ||
89 | }); | ||
90 | acc.finish_resolved() | ||
91 | } | ||
92 | |||
93 | mod handlers { | 93 | mod handlers { |
94 | use crate::{AssistContext, Assists}; | 94 | use crate::{AssistContext, Assists}; |
95 | 95 | ||