Skip to content

Commit 067cb92

Browse files
committed
Simplify
1 parent 61ba56d commit 067cb92

File tree

3 files changed

+3
-23
lines changed

3 files changed

+3
-23
lines changed

crates/ra_assists/src/handlers/auto_import.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
5252
group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
5353
edit.target(auto_import_assets.syntax_under_caret.text_range());
5454
insert_use_statement(
55-
&auto_import_assets.syntax_under_caret,
5655
&auto_import_assets.syntax_under_caret,
5756
&import,
5857
edit.text_edit_builder(),

crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,12 @@ pub(crate) fn replace_qualified_name_with_use(ctx: AssistCtx) -> Option<Assist>
3333
return None;
3434
}
3535

36-
let module = path.syntax().ancestors().find_map(ast::Module::cast);
37-
let position = match module.and_then(|it| it.item_list()) {
38-
Some(item_list) => item_list.syntax().clone(),
39-
None => {
40-
let current_file = path.syntax().ancestors().find_map(ast::SourceFile::cast)?;
41-
current_file.syntax().clone()
42-
}
43-
};
44-
4536
ctx.add_assist(
4637
AssistId("replace_qualified_name_with_use"),
4738
"Replace qualified path with use",
4839
|edit| {
4940
let path_to_import = hir_path.mod_path().clone();
50-
insert_use_statement(
51-
&position,
52-
&path.syntax(),
53-
&path_to_import,
54-
edit.text_edit_builder(),
55-
);
41+
insert_use_statement(path.syntax(), &path_to_import, edit.text_edit_builder());
5642

5743
if let Some(last) = path.segment() {
5844
// Here we are assuming the assist will provide a correct use statement

crates/ra_assists/src/utils/insert_use.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use ra_text_edit::TextEditBuilder;
1515
pub fn insert_use_statement(
1616
// Ideally the position of the cursor, used to
1717
position: &SyntaxNode,
18-
// The statement to use as anchor (last resort)
19-
anchor: &SyntaxNode,
2018
path_to_import: &ModPath,
2119
edit: &mut TextEditBuilder,
2220
) {
@@ -29,7 +27,7 @@ pub fn insert_use_statement(
2927
});
3028

3129
if let Some(container) = container {
32-
let action = best_action_for_target(container, anchor.clone(), &target);
30+
let action = best_action_for_target(container, position.clone(), &target);
3331
make_assist(&action, &target, edit);
3432
}
3533
}
@@ -379,10 +377,7 @@ fn best_action_for_target(
379377
// another item and we use it as anchor.
380378
// If there are no items above, we choose the target path itself as anchor.
381379
// todo: we should include even whitespace blocks as anchor candidates
382-
let anchor = container
383-
.children()
384-
.find(|n| n.text_range().start() < anchor.text_range().start())
385-
.or_else(|| Some(anchor));
380+
let anchor = container.children().next().or_else(|| Some(anchor));
386381

387382
let add_after_anchor = anchor
388383
.clone()

0 commit comments

Comments
 (0)