Add extra insert_use test for pub(crate) re-export handling

This commit is contained in:
Lukas Wirth 2020-09-03 18:44:39 +02:00
parent d29b69cbe6
commit 82f61e6629
2 changed files with 19 additions and 12 deletions

View File

@ -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<Module>,
_enum_module_def: &ModuleDef,
_variant_hir_name: &Name,
_visited_modules_set: &mut FxHashSet<Module>,
) -> Option<()> {
let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>(
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))?,

View File

@ -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<SyntaxElement>, 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<SyntaxElement>, 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() {