From 82f61e6629f709d7f347fd801ef5c31f476ff29e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 3 Sep 2020 18:44:39 +0200 Subject: Add extra insert_use test for pub(crate) re-export handling --- .../handlers/extract_struct_from_enum_variant.rs | 9 +++++---- crates/assists/src/utils/insert_use.rs | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'crates') 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 .any(|(name, _)| name.to_string() == variant_name.to_string()) } +#[allow(dead_code)] fn insert_import( ctx: &AssistContext, builder: &mut AssistBuilder, @@ -174,9 +175,9 @@ fn update_reference( builder: &mut AssistBuilder, reference: Reference, source_file: &SourceFile, - enum_module_def: &ModuleDef, - variant_hir_name: &Name, - visited_modules_set: &mut FxHashSet, + _enum_module_def: &ModuleDef, + _variant_hir_name: &Name, + _visited_modules_set: &mut FxHashSet, ) -> Option<()> { let path_expr: ast::PathExpr = find_node_at_offset::( source_file.syntax(), @@ -185,7 +186,7 @@ fn update_reference( let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?; let list = call.arg_list()?; let segment = path_expr.path()?.segment()?; - let module = ctx.sema.scope(&path_expr.syntax()).module()?; + let _module = ctx.sema.scope(&path_expr.syntax()).module()?; let list_range = list.syntax().text_range(); let inside_list_range = TextRange::new( 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 @@ +//! Handle syntactic aspects of inserting a new `use`. use std::iter::{self, successors}; use algo::skip_trivia_token; @@ -10,7 +11,6 @@ use syntax::{ ast::{self, make, AstNode}, Direction, InsertPosition, SyntaxElement, SyntaxNode, T, }; - use test_utils::mark; #[derive(Debug)] @@ -55,7 +55,7 @@ impl ImportScope { fn first_insert_pos(&self) -> (InsertPosition, AddBlankLine) { match self { ImportScope::File(_) => (InsertPosition::First, AddBlankLine::AfterTwice), - // don't insert the impotrs before the item lists curly brace + // don't insert the imports before the item list's opening curly brace ImportScope::Module(item_list) => item_list .l_curly_token() .map(|b| (InsertPosition::After(b.into()), AddBlankLine::Around)) @@ -64,7 +64,7 @@ impl ImportScope { } fn insert_pos_after_inner_attribute(&self) -> (InsertPosition, AddBlankLine) { - // check if the scope has a inner attributes, we dont want to insert in front of it + // check if the scope has inner attributes, we dont want to insert in front of them match self .as_syntax_node() .children() @@ -119,7 +119,7 @@ pub(crate) fn insert_use( } if let ident_level @ 1..=usize::MAX = scope.indent_level().0 as usize { - // TODO: this alone doesnt properly re-align all cases + // FIXME: this alone doesnt properly re-align all cases buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into()); } buf.push(use_item.syntax().clone().into()); @@ -530,8 +530,6 @@ fn main() {}", #[test] fn insert_after_inner_attr() { - // empty files will get two trailing newlines - // this is due to the test case insert_no_imports above check_full( "foo::bar", r"#![allow(unused_imports)]", @@ -543,8 +541,6 @@ use foo::bar;", #[test] fn insert_after_inner_attr2() { - // empty files will get two trailing newlines - // this is due to the test case insert_no_imports above check_full( "foo::bar", r"#![allow(unused_imports)] @@ -647,6 +643,16 @@ use std::io;", ) } + #[test] + fn merge_groups_skip_pub_crate() { + check_full( + "std::io", + r"pub(crate) use std::fmt::{Result, Display};", + r"pub(crate) use std::fmt::{Result, Display}; +use std::io;", + ) + } + #[test] #[ignore] // FIXME: Support this fn split_out_merge() { -- cgit v1.2.3