Skip to content

Commit 70930d3

Browse files
committed
Remove set_cursor
1 parent 4ac0abd commit 70930d3

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

crates/ra_assists/src/assist_context.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,13 @@ impl Assists {
171171

172172
pub(crate) struct AssistBuilder {
173173
edit: TextEditBuilder,
174-
cursor_position: Option<TextSize>,
175174
file: FileId,
176175
is_snippet: bool,
177176
}
178177

179178
impl AssistBuilder {
180179
pub(crate) fn new(file: FileId) -> AssistBuilder {
181-
AssistBuilder {
182-
edit: TextEditBuilder::default(),
183-
cursor_position: None,
184-
file,
185-
is_snippet: false,
186-
}
180+
AssistBuilder { edit: TextEditBuilder::default(), file, is_snippet: false }
187181
}
188182

189183
/// Remove specified `range` of text.
@@ -241,10 +235,6 @@ impl AssistBuilder {
241235
algo::diff(&node, &new).into_text_edit(&mut self.edit)
242236
}
243237

244-
/// Specify desired position of the cursor after the assist is applied.
245-
pub(crate) fn set_cursor(&mut self, offset: TextSize) {
246-
self.cursor_position = Some(offset)
247-
}
248238
// FIXME: better API
249239
pub(crate) fn set_file(&mut self, assist_file: FileId) {
250240
self.file = assist_file;
@@ -258,12 +248,8 @@ impl AssistBuilder {
258248

259249
fn finish(self, change_label: String) -> SourceChange {
260250
let edit = self.edit.finish();
261-
if edit.is_empty() && self.cursor_position.is_none() {
262-
panic!("Only call `add_assist` if the assist can be applied")
263-
}
264-
let mut res =
265-
SingleFileChange { label: change_label, edit, cursor_position: self.cursor_position }
266-
.into_source_change(self.file);
251+
let mut res = SingleFileChange { label: change_label, edit, cursor_position: None }
252+
.into_source_change(self.file);
267253
if self.is_snippet {
268254
res.is_snippet = true;
269255
}

crates/ra_assists/src/handlers/unwrap_block.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
6262
let range_to_del_else_if = TextRange::new(ancestor_then_branch.syntax().text_range().end(), l_curly_token.text_range().start());
6363
let range_to_del_rest = TextRange::new(then_branch.syntax().text_range().end(), if_expr.syntax().text_range().end());
6464

65-
edit.set_cursor(ancestor_then_branch.syntax().text_range().end());
6665
edit.delete(range_to_del_rest);
6766
edit.delete(range_to_del_else_if);
6867
edit.replace(target, update_expr_string(then_branch.to_string(), &[' ', '{']));
@@ -79,7 +78,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
7978
return acc.add(assist_id, assist_label, target, |edit| {
8079
let range_to_del = TextRange::new(then_branch.syntax().text_range().end(), l_curly_token.text_range().start());
8180

82-
edit.set_cursor(then_branch.syntax().text_range().end());
8381
edit.delete(range_to_del);
8482
edit.replace(target, update_expr_string(else_block.to_string(), &[' ', '{']));
8583
});
@@ -97,8 +95,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
9795

9896
let target = expr_to_unwrap.syntax().text_range();
9997
acc.add(assist_id, assist_label, target, |edit| {
100-
edit.set_cursor(expr.syntax().text_range().start());
101-
10298
edit.replace(
10399
expr.syntax().text_range(),
104100
update_expr_string(expr_to_unwrap.to_string(), &[' ', '{', '\n']),
@@ -154,7 +150,7 @@ mod tests {
154150
r#"
155151
fn main() {
156152
bar();
157-
<|>foo();
153+
foo();
158154
159155
//comment
160156
bar();
@@ -188,7 +184,7 @@ mod tests {
188184
189185
//comment
190186
bar();
191-
}<|>
187+
}
192188
println!("bar");
193189
}
194190
"#,
@@ -222,7 +218,7 @@ mod tests {
222218
223219
//comment
224220
//bar();
225-
}<|>
221+
}
226222
println!("bar");
227223
}
228224
"#,
@@ -258,7 +254,7 @@ mod tests {
258254
//bar();
259255
} else if false {
260256
println!("bar");
261-
}<|>
257+
}
262258
println!("foo");
263259
}
264260
"#,
@@ -298,7 +294,7 @@ mod tests {
298294
println!("bar");
299295
} else if true {
300296
println!("foo");
301-
}<|>
297+
}
302298
println!("else");
303299
}
304300
"#,
@@ -336,7 +332,7 @@ mod tests {
336332
//bar();
337333
} else if false {
338334
println!("bar");
339-
}<|>
335+
}
340336
println!("foo");
341337
}
342338
"#,
@@ -383,7 +379,7 @@ mod tests {
383379
"#,
384380
r#"
385381
fn main() {
386-
<|>if true {
382+
if true {
387383
foo();
388384
389385
//comment
@@ -417,7 +413,7 @@ mod tests {
417413
r#"
418414
fn main() {
419415
for i in 0..5 {
420-
<|>foo();
416+
foo();
421417
422418
//comment
423419
bar();
@@ -447,7 +443,7 @@ mod tests {
447443
"#,
448444
r#"
449445
fn main() {
450-
<|>if true {
446+
if true {
451447
foo();
452448
453449
//comment
@@ -480,7 +476,7 @@ mod tests {
480476
"#,
481477
r#"
482478
fn main() {
483-
<|>if true {
479+
if true {
484480
foo();
485481
486482
//comment

0 commit comments

Comments
 (0)