aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assist_ctx.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/assist_ctx.rs')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs17
1 files changed, 4 insertions, 13 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index 83dd270c6..600e5689c 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -94,9 +94,10 @@ impl<'a> AssistCtx<'a> {
94 self, 94 self,
95 id: AssistId, 95 id: AssistId,
96 label: impl Into<String>, 96 label: impl Into<String>,
97 target: TextRange,
97 f: impl FnOnce(&mut ActionBuilder), 98 f: impl FnOnce(&mut ActionBuilder),
98 ) -> Option<Assist> { 99 ) -> Option<Assist> {
99 let label = AssistLabel::new(id, label.into(), None); 100 let label = AssistLabel::new(id, label.into(), None, target);
100 101
101 let mut info = AssistInfo::new(label); 102 let mut info = AssistInfo::new(label);
102 if self.should_compute_edit { 103 if self.should_compute_edit {
@@ -152,9 +153,10 @@ impl<'a> AssistGroup<'a> {
152 &mut self, 153 &mut self,
153 id: AssistId, 154 id: AssistId,
154 label: impl Into<String>, 155 label: impl Into<String>,
156 target: TextRange,
155 f: impl FnOnce(&mut ActionBuilder), 157 f: impl FnOnce(&mut ActionBuilder),
156 ) { 158 ) {
157 let label = AssistLabel::new(id, label.into(), Some(self.group.clone())); 159 let label = AssistLabel::new(id, label.into(), Some(self.group.clone()), target);
158 160
159 let mut info = AssistInfo::new(label).with_group(self.group.clone()); 161 let mut info = AssistInfo::new(label).with_group(self.group.clone());
160 if self.ctx.should_compute_edit { 162 if self.ctx.should_compute_edit {
@@ -181,7 +183,6 @@ impl<'a> AssistGroup<'a> {
181pub(crate) struct ActionBuilder<'a, 'b> { 183pub(crate) struct ActionBuilder<'a, 'b> {
182 edit: TextEditBuilder, 184 edit: TextEditBuilder,
183 cursor_position: Option<TextSize>, 185 cursor_position: Option<TextSize>,
184 target: Option<TextRange>,
185 file: AssistFile, 186 file: AssistFile,
186 ctx: &'a AssistCtx<'b>, 187 ctx: &'a AssistCtx<'b>,
187} 188}
@@ -191,7 +192,6 @@ impl<'a, 'b> ActionBuilder<'a, 'b> {
191 Self { 192 Self {
192 edit: TextEditBuilder::default(), 193 edit: TextEditBuilder::default(),
193 cursor_position: None, 194 cursor_position: None,
194 target: None,
195 file: AssistFile::default(), 195 file: AssistFile::default(),
196 ctx, 196 ctx,
197 } 197 }
@@ -237,14 +237,6 @@ impl<'a, 'b> ActionBuilder<'a, 'b> {
237 self.cursor_position = Some(offset) 237 self.cursor_position = Some(offset)
238 } 238 }
239 239
240 /// Specify that the assist should be active withing the `target` range.
241 ///
242 /// Target ranges are used to sort assists: the smaller the target range,
243 /// the more specific assist is, and so it should be sorted first.
244 pub(crate) fn target(&mut self, target: TextRange) {
245 self.target = Some(target)
246 }
247
248 /// Get access to the raw `TextEditBuilder`. 240 /// Get access to the raw `TextEditBuilder`.
249 pub(crate) fn text_edit_builder(&mut self) -> &mut TextEditBuilder { 241 pub(crate) fn text_edit_builder(&mut self) -> &mut TextEditBuilder {
250 &mut self.edit 242 &mut self.edit
@@ -267,7 +259,6 @@ impl<'a, 'b> ActionBuilder<'a, 'b> {
267 AssistAction { 259 AssistAction {
268 edit: self.edit.finish(), 260 edit: self.edit.finish(),
269 cursor_position: self.cursor_position, 261 cursor_position: self.cursor_position,
270 target: self.target,
271 file: self.file, 262 file: self.file,
272 } 263 }
273 } 264 }