aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r--crates/ra_assists/src/lib.rs80
1 files changed, 40 insertions, 40 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 011613762..b6dc7cb1b 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -29,8 +29,11 @@ pub(crate) use crate::assist_context::{AssistContext, Assists};
29#[derive(Debug, Clone, Copy, PartialEq, Eq)] 29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub struct AssistId(pub &'static str); 30pub struct AssistId(pub &'static str);
31 31
32#[derive(Clone, Debug)]
33pub struct GroupLabel(pub String);
34
32#[derive(Debug, Clone)] 35#[derive(Debug, Clone)]
33pub struct AssistLabel { 36pub struct Assist {
34 pub id: AssistId, 37 pub id: AssistId,
35 /// Short description of the assist, as shown in the UI. 38 /// Short description of the assist, as shown in the UI.
36 pub label: String, 39 pub label: String,
@@ -40,56 +43,53 @@ pub struct AssistLabel {
40 pub target: TextRange, 43 pub target: TextRange,
41} 44}
42 45
43#[derive(Clone, Debug)] 46#[derive(Debug, Clone)]
44pub struct GroupLabel(pub String); 47pub struct ResolvedAssist {
48 pub assist: Assist,
49 pub source_change: SourceChange,
50}
51
52impl 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 }
45 80
46impl AssistLabel {
47 pub(crate) fn new( 81 pub(crate) fn new(
48 id: AssistId, 82 id: AssistId,
49 label: String, 83 label: String,
50 group: Option<GroupLabel>, 84 group: Option<GroupLabel>,
51 target: TextRange, 85 target: TextRange,
52 ) -> AssistLabel { 86 ) -> Assist {
53 // FIXME: make fields private, so that this invariant can't be broken 87 // FIXME: make fields private, so that this invariant can't be broken
54 assert!(label.starts_with(|c: char| c.is_uppercase())); 88 assert!(label.starts_with(|c: char| c.is_uppercase()));
55 AssistLabel { id, label, group, target } 89 Assist { id, label, group, target }
56 } 90 }
57} 91}
58 92
59#[derive(Debug, Clone)]
60pub struct ResolvedAssist {
61 pub label: AssistLabel,
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.
69pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> {
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.
83pub 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
93mod handlers { 93mod handlers {
94 use crate::{AssistContext, Assists}; 94 use crate::{AssistContext, Assists};
95 95