aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/assist_context.rs16
-rw-r--r--crates/ra_assists/src/lib.rs12
-rw-r--r--crates/ra_assists/src/tests.rs14
-rw-r--r--crates/ra_ide/src/lib.rs6
4 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs
index 203ad1273..81052ab49 100644
--- a/crates/ra_assists/src/assist_context.rs
+++ b/crates/ra_assists/src/assist_context.rs
@@ -15,7 +15,7 @@ use ra_syntax::{
15}; 15};
16use ra_text_edit::TextEditBuilder; 16use ra_text_edit::TextEditBuilder;
17 17
18use crate::{AssistId, AssistLabel, GroupLabel, ResolvedAssist}; 18use crate::{Assist, AssistId, GroupLabel, ResolvedAssist};
19 19
20/// `AssistContext` allows to apply an assist or check if it could be applied. 20/// `AssistContext` allows to apply an assist or check if it could be applied.
21/// 21///
@@ -91,7 +91,7 @@ impl<'a> AssistContext<'a> {
91pub(crate) struct Assists { 91pub(crate) struct Assists {
92 resolve: bool, 92 resolve: bool,
93 file: FileId, 93 file: FileId,
94 buf: Vec<(AssistLabel, Option<SourceChange>)>, 94 buf: Vec<(Assist, Option<SourceChange>)>,
95} 95}
96 96
97impl Assists { 97impl Assists {
@@ -102,7 +102,7 @@ impl Assists {
102 Assists { resolve: false, file: ctx.frange.file_id, buf: Vec::new() } 102 Assists { resolve: false, file: ctx.frange.file_id, buf: Vec::new() }
103 } 103 }
104 104
105 pub(crate) fn finish_unresolved(self) -> Vec<AssistLabel> { 105 pub(crate) fn finish_unresolved(self) -> Vec<Assist> {
106 assert!(!self.resolve); 106 assert!(!self.resolve);
107 self.finish() 107 self.finish()
108 .into_iter() 108 .into_iter()
@@ -117,7 +117,7 @@ impl Assists {
117 assert!(self.resolve); 117 assert!(self.resolve);
118 self.finish() 118 self.finish()
119 .into_iter() 119 .into_iter()
120 .map(|(label, edit)| ResolvedAssist { label, source_change: edit.unwrap() }) 120 .map(|(label, edit)| ResolvedAssist { assist: label, source_change: edit.unwrap() })
121 .collect() 121 .collect()
122 } 122 }
123 123
@@ -128,7 +128,7 @@ impl Assists {
128 target: TextRange, 128 target: TextRange,
129 f: impl FnOnce(&mut AssistBuilder), 129 f: impl FnOnce(&mut AssistBuilder),
130 ) -> Option<()> { 130 ) -> Option<()> {
131 let label = AssistLabel::new(id, label.into(), None, target); 131 let label = Assist::new(id, label.into(), None, target);
132 self.add_impl(label, f) 132 self.add_impl(label, f)
133 } 133 }
134 pub(crate) fn add_group( 134 pub(crate) fn add_group(
@@ -139,10 +139,10 @@ impl Assists {
139 target: TextRange, 139 target: TextRange,
140 f: impl FnOnce(&mut AssistBuilder), 140 f: impl FnOnce(&mut AssistBuilder),
141 ) -> Option<()> { 141 ) -> Option<()> {
142 let label = AssistLabel::new(id, label.into(), Some(group.clone()), target); 142 let label = Assist::new(id, label.into(), Some(group.clone()), target);
143 self.add_impl(label, f) 143 self.add_impl(label, f)
144 } 144 }
145 fn add_impl(&mut self, label: AssistLabel, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { 145 fn add_impl(&mut self, label: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> {
146 let change_label = label.label.clone(); 146 let change_label = label.label.clone();
147 let source_change = if self.resolve { 147 let source_change = if self.resolve {
148 let mut builder = AssistBuilder::new(self.file); 148 let mut builder = AssistBuilder::new(self.file);
@@ -156,7 +156,7 @@ impl Assists {
156 Some(()) 156 Some(())
157 } 157 }
158 158
159 fn finish(mut self) -> Vec<(AssistLabel, Option<SourceChange>)> { 159 fn finish(mut self) -> Vec<(Assist, Option<SourceChange>)> {
160 self.buf.sort_by_key(|(label, _edit)| label.target.len()); 160 self.buf.sort_by_key(|(label, _edit)| label.target.len());
161 self.buf 161 self.buf
162 } 162 }
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 011613762..a91975d8c 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -30,7 +30,7 @@ pub(crate) use crate::assist_context::{AssistContext, Assists};
30pub struct AssistId(pub &'static str); 30pub struct AssistId(pub &'static str);
31 31
32#[derive(Debug, Clone)] 32#[derive(Debug, Clone)]
33pub struct AssistLabel { 33pub struct Assist {
34 pub id: AssistId, 34 pub id: AssistId,
35 /// Short description of the assist, as shown in the UI. 35 /// Short description of the assist, as shown in the UI.
36 pub label: String, 36 pub label: String,
@@ -43,22 +43,22 @@ pub struct AssistLabel {
43#[derive(Clone, Debug)] 43#[derive(Clone, Debug)]
44pub struct GroupLabel(pub String); 44pub struct GroupLabel(pub String);
45 45
46impl AssistLabel { 46impl Assist {
47 pub(crate) fn new( 47 pub(crate) fn new(
48 id: AssistId, 48 id: AssistId,
49 label: String, 49 label: String,
50 group: Option<GroupLabel>, 50 group: Option<GroupLabel>,
51 target: TextRange, 51 target: TextRange,
52 ) -> AssistLabel { 52 ) -> Assist {
53 // FIXME: make fields private, so that this invariant can't be broken 53 // FIXME: make fields private, so that this invariant can't be broken
54 assert!(label.starts_with(|c: char| c.is_uppercase())); 54 assert!(label.starts_with(|c: char| c.is_uppercase()));
55 AssistLabel { id, label, group, target } 55 Assist { id, label, group, target }
56 } 56 }
57} 57}
58 58
59#[derive(Debug, Clone)] 59#[derive(Debug, Clone)]
60pub struct ResolvedAssist { 60pub struct ResolvedAssist {
61 pub label: AssistLabel, 61 pub assist: Assist,
62 pub source_change: SourceChange, 62 pub source_change: SourceChange,
63} 63}
64 64
@@ -66,7 +66,7 @@ pub struct ResolvedAssist {
66/// 66///
67/// Assists are returned in the "unresolved" state, that is only labels are 67/// Assists are returned in the "unresolved" state, that is only labels are
68/// returned, without actual edits. 68/// returned, without actual edits.
69pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> { 69pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<Assist> {
70 let sema = Semantics::new(db); 70 let sema = Semantics::new(db);
71 let ctx = AssistContext::new(sema, range); 71 let ctx = AssistContext::new(sema, range);
72 let mut acc = Assists::new_unresolved(&ctx); 72 let mut acc = Assists::new_unresolved(&ctx);
diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs
index 45b2d9733..a81c54d07 100644
--- a/crates/ra_assists/src/tests.rs
+++ b/crates/ra_assists/src/tests.rs
@@ -43,14 +43,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
43 43
44 let mut assist = resolved_assists(&db, frange) 44 let mut assist = resolved_assists(&db, frange)
45 .into_iter() 45 .into_iter()
46 .find(|assist| assist.label.id.0 == assist_id) 46 .find(|assist| assist.assist.id.0 == assist_id)
47 .unwrap_or_else(|| { 47 .unwrap_or_else(|| {
48 panic!( 48 panic!(
49 "\n\nAssist is not applicable: {}\nAvailable assists: {}", 49 "\n\nAssist is not applicable: {}\nAvailable assists: {}",
50 assist_id, 50 assist_id,
51 resolved_assists(&db, frange) 51 resolved_assists(&db, frange)
52 .into_iter() 52 .into_iter()
53 .map(|assist| assist.label.id.0) 53 .map(|assist| assist.assist.id.0)
54 .collect::<Vec<_>>() 54 .collect::<Vec<_>>()
55 .join(", ") 55 .join(", ")
56 ) 56 )
@@ -119,7 +119,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) {
119 assert_eq_text!(after, &actual); 119 assert_eq_text!(after, &actual);
120 } 120 }
121 (Some(assist), ExpectedResult::Target(target)) => { 121 (Some(assist), ExpectedResult::Target(target)) => {
122 let range = assist.label.target; 122 let range = assist.assist.target;
123 assert_eq_text!(&text_without_caret[range], target); 123 assert_eq_text!(&text_without_caret[range], target);
124 } 124 }
125 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), 125 (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"),
@@ -140,10 +140,10 @@ fn assist_order_field_struct() {
140 let mut assists = assists.iter(); 140 let mut assists = assists.iter();
141 141
142 assert_eq!( 142 assert_eq!(
143 assists.next().expect("expected assist").label.label, 143 assists.next().expect("expected assist").assist.label,
144 "Change visibility to pub(crate)" 144 "Change visibility to pub(crate)"
145 ); 145 );
146 assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); 146 assert_eq!(assists.next().expect("expected assist").assist.label, "Add `#[derive]`");
147} 147}
148 148
149#[test] 149#[test]
@@ -162,6 +162,6 @@ fn assist_order_if_expr() {
162 let assists = resolved_assists(&db, frange); 162 let assists = resolved_assists(&db, frange);
163 let mut assists = assists.iter(); 163 let mut assists = assists.iter();
164 164
165 assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); 165 assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable");
166 assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); 166 assert_eq!(assists.next().expect("expected assist").assist.label, "Replace with match");
167} 167}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 737f87109..0e15f1ccd 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -475,9 +475,9 @@ impl Analysis {
475 ra_assists::resolved_assists(db, frange) 475 ra_assists::resolved_assists(db, frange)
476 .into_iter() 476 .into_iter()
477 .map(|assist| Assist { 477 .map(|assist| Assist {
478 id: assist.label.id, 478 id: assist.assist.id,
479 label: assist.label.label, 479 label: assist.assist.label,
480 group_label: assist.label.group.map(|it| it.0), 480 group_label: assist.assist.group.map(|it| it.0),
481 source_change: assist.source_change, 481 source_change: assist.source_change,
482 }) 482 })
483 .collect() 483 .collect()