diff options
author | Lukas Wirth <[email protected]> | 2020-09-03 13:22:22 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-09-03 17:36:08 +0100 |
commit | c1925df7fc91a171925ecb59b9f1895ee59ce72f (patch) | |
tree | 475182f8b2f91a200cfa1662f7407242b6220cb6 /crates/assists/src/utils/insert_use.rs | |
parent | 952f3856822d471cf5062e82f544c901c385f3ae (diff) |
Replace insert_use_statement with the new insert_use
Diffstat (limited to 'crates/assists/src/utils/insert_use.rs')
-rw-r--r-- | crates/assists/src/utils/insert_use.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 030a5a935..f2acda6f3 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs | |||
@@ -18,9 +18,10 @@ pub(crate) fn find_insert_use_container( | |||
18 | ) -> Option<Either<ast::ItemList, ast::SourceFile>> { | 18 | ) -> Option<Either<ast::ItemList, ast::SourceFile>> { |
19 | ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| { | 19 | ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| { |
20 | if let Some(module) = ast::Module::cast(n.clone()) { | 20 | if let Some(module) = ast::Module::cast(n.clone()) { |
21 | return module.item_list().map(Either::Left); | 21 | module.item_list().map(Either::Left) |
22 | } else { | ||
23 | Some(Either::Right(ast::SourceFile::cast(n)?)) | ||
22 | } | 24 | } |
23 | Some(Either::Right(ast::SourceFile::cast(n)?)) | ||
24 | }) | 25 | }) |
25 | } | 26 | } |
26 | 27 | ||
@@ -92,6 +93,7 @@ fn use_tree_list_is_nested(tl: &ast::UseTreeList) -> bool { | |||
92 | }) | 93 | }) |
93 | } | 94 | } |
94 | 95 | ||
96 | // FIXME: currently this merely prepends the new tree into old, ideally it would insert the items in a sorted fashion | ||
95 | pub fn try_merge_trees( | 97 | pub fn try_merge_trees( |
96 | old: &ast::UseTree, | 98 | old: &ast::UseTree, |
97 | new: &ast::UseTree, | 99 | new: &ast::UseTree, |
@@ -486,7 +488,7 @@ use std::io;", | |||
486 | check_full( | 488 | check_full( |
487 | "std::foo::bar::Baz", | 489 | "std::foo::bar::Baz", |
488 | r"use std::foo::bar::Qux;", | 490 | r"use std::foo::bar::Qux;", |
489 | r"use std::foo::bar::{Baz, Qux};", | 491 | r"use std::foo::bar::{Qux, Baz};", |
490 | ) | 492 | ) |
491 | } | 493 | } |
492 | 494 | ||
@@ -495,7 +497,7 @@ use std::io;", | |||
495 | check_last( | 497 | check_last( |
496 | "std::foo::bar::Baz", | 498 | "std::foo::bar::Baz", |
497 | r"use std::foo::bar::Qux;", | 499 | r"use std::foo::bar::Qux;", |
498 | r"use std::foo::bar::{Baz, Qux};", | 500 | r"use std::foo::bar::{Qux, Baz};", |
499 | ) | 501 | ) |
500 | } | 502 | } |
501 | 503 | ||
@@ -504,7 +506,7 @@ use std::io;", | |||
504 | check_full( | 506 | check_full( |
505 | "std::foo::bar::Baz", | 507 | "std::foo::bar::Baz", |
506 | r"use std::foo::bar::{Qux, Quux};", | 508 | r"use std::foo::bar::{Qux, Quux};", |
507 | r"use std::foo::bar::{Baz, Quux, Qux};", | 509 | r"use std::foo::bar::{Qux, Quux, Baz};", |
508 | ) | 510 | ) |
509 | } | 511 | } |
510 | 512 | ||
@@ -513,7 +515,7 @@ use std::io;", | |||
513 | check_last( | 515 | check_last( |
514 | "std::foo::bar::Baz", | 516 | "std::foo::bar::Baz", |
515 | r"use std::foo::bar::{Qux, Quux};", | 517 | r"use std::foo::bar::{Qux, Quux};", |
516 | r"use std::foo::bar::{Baz, Quux, Qux};", | 518 | r"use std::foo::bar::{Qux, Quux, Baz};", |
517 | ) | 519 | ) |
518 | } | 520 | } |
519 | 521 | ||
@@ -522,7 +524,7 @@ use std::io;", | |||
522 | check_full( | 524 | check_full( |
523 | "std::foo::bar::Baz", | 525 | "std::foo::bar::Baz", |
524 | r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", | 526 | r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", |
525 | r"use std::foo::bar::{Baz, quux::{Fez, Fizz}, Qux};", | 527 | r"use std::foo::bar::{Qux, quux::{Fez, Fizz}, Baz};", |
526 | ) | 528 | ) |
527 | } | 529 | } |
528 | 530 | ||
@@ -532,7 +534,7 @@ use std::io;", | |||
532 | "std::foo::bar::Baz", | 534 | "std::foo::bar::Baz", |
533 | r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", | 535 | r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};", |
534 | r"use std::foo::bar::Baz; | 536 | r"use std::foo::bar::Baz; |
535 | use std::foo::bar::{quux::{Fez, Fizz}, Qux};", | 537 | use std::foo::bar::{Qux, quux::{Fez, Fizz}};", |
536 | ) | 538 | ) |
537 | } | 539 | } |
538 | 540 | ||