aboutsummaryrefslogtreecommitdiff
path: root/crates
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
parentd29b69cbe61d20556c55e4f6a53da0784df8b6d0 (diff)
Add extra insert_use test for pub(crate) re-export handling
Diffstat (limited to 'crates')
-rw-r--r--crates/assists/src/handlers/extract_struct_from_enum_variant.rs9
-rw-r--r--crates/assists/src/utils/insert_use.rs22
2 files changed, 19 insertions, 12 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
index eb812c1c9..80c62d8bb 100644
--- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -97,6 +97,7 @@ fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVari
97 .any(|(name, _)| name.to_string() == variant_name.to_string()) 97 .any(|(name, _)| name.to_string() == variant_name.to_string())
98} 98}
99 99
100#[allow(dead_code)]
100fn insert_import( 101fn insert_import(
101 ctx: &AssistContext, 102 ctx: &AssistContext,
102 builder: &mut AssistBuilder, 103 builder: &mut AssistBuilder,
@@ -174,9 +175,9 @@ fn update_reference(
174 builder: &mut AssistBuilder, 175 builder: &mut AssistBuilder,
175 reference: Reference, 176 reference: Reference,
176 source_file: &SourceFile, 177 source_file: &SourceFile,
177 enum_module_def: &ModuleDef, 178 _enum_module_def: &ModuleDef,
178 variant_hir_name: &Name, 179 _variant_hir_name: &Name,
179 visited_modules_set: &mut FxHashSet<Module>, 180 _visited_modules_set: &mut FxHashSet<Module>,
180) -> Option<()> { 181) -> Option<()> {
181 let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>( 182 let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>(
182 source_file.syntax(), 183 source_file.syntax(),
@@ -185,7 +186,7 @@ fn update_reference(
185 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?; 186 let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
186 let list = call.arg_list()?; 187 let list = call.arg_list()?;
187 let segment = path_expr.path()?.segment()?; 188 let segment = path_expr.path()?.segment()?;
188 let module = ctx.sema.scope(&path_expr.syntax()).module()?; 189 let _module = ctx.sema.scope(&path_expr.syntax()).module()?;
189 let list_range = list.syntax().text_range(); 190 let list_range = list.syntax().text_range();
190 let inside_list_range = TextRange::new( 191 let inside_list_range = TextRange::new(
191 list_range.start().checked_add(TextSize::from(1))?, 192 list_range.start().checked_add(TextSize::from(1))?,
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(