aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/utils/insert_use.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-09-03 17:44:39 +0100
committerLukas Wirth <[email protected]>2020-09-03 19:26:27 +0100
commit82f61e6629f709d7f347fd801ef5c31f476ff29e (patch)
tree0e632f111245b77e33799c2e51bad3fda59ed66f /crates/assists/src/utils/insert_use.rs
parentd29b69cbe61d20556c55e4f6a53da0784df8b6d0 (diff)
Add extra insert_use test for pub(crate) re-export handling
Diffstat (limited to 'crates/assists/src/utils/insert_use.rs')
-rw-r--r--crates/assists/src/utils/insert_use.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs
index 40ff31075..8a4c8520d 100644
--- a/crates/assists/src/utils/insert_use.rs
+++ b/crates/assists/src/utils/insert_use.rs
@@ -1,3 +1,4 @@
1//! Handle syntactic aspects of inserting a new `use`.
1use std::iter::{self, successors}; 2use std::iter::{self, successors};
2 3
3use algo::skip_trivia_token; 4use algo::skip_trivia_token;
@@ -10,7 +11,6 @@ use syntax::{
10 ast::{self, make, AstNode}, 11 ast::{self, make, AstNode},
11 Direction, InsertPosition, SyntaxElement, SyntaxNode, T, 12 Direction, InsertPosition, SyntaxElement, SyntaxNode, T,
12}; 13};
13
14use test_utils::mark; 14use test_utils::mark;
15 15
16#[derive(Debug)] 16#[derive(Debug)]
@@ -55,7 +55,7 @@ impl ImportScope {
55 fn first_insert_pos(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) { 55 fn first_insert_pos(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
56 match self { 56 match self {
57 ImportScope::File(_) => (InsertPosition::First, AddBlankLine::AfterTwice), 57 ImportScope::File(_) => (InsertPosition::First, AddBlankLine::AfterTwice),
58 // don't insert the impotrs before the item lists curly brace 58 // don't insert the imports before the item list's opening curly brace
59 ImportScope::Module(item_list) => item_list 59 ImportScope::Module(item_list) => item_list
60 .l_curly_token() 60 .l_curly_token()
61 .map(|b| (InsertPosition::After(b.into()), AddBlankLine::Around)) 61 .map(|b| (InsertPosition::After(b.into()), AddBlankLine::Around))
@@ -64,7 +64,7 @@ impl ImportScope {
64 } 64 }
65 65
66 fn insert_pos_after_inner_attribute(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) { 66 fn insert_pos_after_inner_attribute(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
67 // check if the scope has a inner attributes, we dont want to insert in front of it 67 // check if the scope has inner attributes, we dont want to insert in front of them
68 match self 68 match self
69 .as_syntax_node() 69 .as_syntax_node()
70 .children() 70 .children()
@@ -119,7 +119,7 @@ pub(crate) fn insert_use(
119 } 119 }
120 120
121 if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize { 121 if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize {
122 // TODO: this alone doesnt properly re-align all cases 122 // FIXME: this alone doesnt properly re-align all cases
123 buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into()); 123 buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into());
124 } 124 }
125 buf.push(use_item.syntax().clone().into()); 125 buf.push(use_item.syntax().clone().into());
@@ -530,8 +530,6 @@ fn main() {}",
530 530
531 #[test] 531 #[test]
532 fn insert_after_inner_attr() { 532 fn insert_after_inner_attr() {
533 // empty files will get two trailing newlines
534 // this is due to the test case insert_no_imports above
535 check_full( 533 check_full(
536 "foo::bar", 534 "foo::bar",
537 r"#![allow(unused_imports)]", 535 r"#![allow(unused_imports)]",
@@ -543,8 +541,6 @@ use foo::bar;",
543 541
544 #[test] 542 #[test]
545 fn insert_after_inner_attr2() { 543 fn insert_after_inner_attr2() {
546 // empty files will get two trailing newlines
547 // this is due to the test case insert_no_imports above
548 check_full( 544 check_full(
549 "foo::bar", 545 "foo::bar",
550 r"#![allow(unused_imports)] 546 r"#![allow(unused_imports)]
@@ -648,6 +644,16 @@ use std::io;",
648 } 644 }
649 645
650 #[test] 646 #[test]
647 fn merge_groups_skip_pub_crate() {
648 check_full(
649 "std::io",
650 r"pub(crate) use std::fmt::{Result, Display};",
651 r"pub(crate) use std::fmt::{Result, Display};
652use std::io;",
653 )
654 }
655
656 #[test]
651 #[ignore] // FIXME: Support this 657 #[ignore] // FIXME: Support this
652 fn split_out_merge() { 658 fn split_out_merge() {
653 check_last( 659 check_last(