Skip to content

Commit 82f61e6

Browse files
committed
Add extra insert_use test for pub(crate) re-export handling
1 parent d29b69c commit 82f61e6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVari
9797
.any(|(name, _)| name.to_string() == variant_name.to_string())
9898
}
9999

100+
#[allow(dead_code)]
100101
fn insert_import(
101102
ctx: &AssistContext,
102103
builder: &mut AssistBuilder,
@@ -174,9 +175,9 @@ fn update_reference(
174175
builder: &mut AssistBuilder,
175176
reference: Reference,
176177
source_file: &SourceFile,
177-
enum_module_def: &ModuleDef,
178-
variant_hir_name: &Name,
179-
visited_modules_set: &mut FxHashSet<Module>,
178+
_enum_module_def: &ModuleDef,
179+
_variant_hir_name: &Name,
180+
_visited_modules_set: &mut FxHashSet<Module>,
180181
) -> Option<()> {
181182
let path_expr: ast::PathExpr = find_node_at_offset::<ast::PathExpr>(
182183
source_file.syntax(),
@@ -185,7 +186,7 @@ fn update_reference(
185186
let call = path_expr.syntax().parent().and_then(ast::CallExpr::cast)?;
186187
let list = call.arg_list()?;
187188
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()?;
189190
let list_range = list.syntax().text_range();
190191
let inside_list_range = TextRange::new(
191192
list_range.start().checked_add(TextSize::from(1))?,

crates/assists/src/utils/insert_use.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Handle syntactic aspects of inserting a new `use`.
12
use std::iter::{self, successors};
23

34
use algo::skip_trivia_token;
@@ -10,7 +11,6 @@ use syntax::{
1011
ast::{self, make, AstNode},
1112
Direction, InsertPosition, SyntaxElement, SyntaxNode, T,
1213
};
13-
1414
use test_utils::mark;
1515

1616
#[derive(Debug)]
@@ -55,7 +55,7 @@ impl ImportScope {
5555
fn first_insert_pos(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
5656
match self {
5757
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
5959
ImportScope::Module(item_list) => item_list
6060
.l_curly_token()
6161
.map(|b| (InsertPosition::After(b.into()), AddBlankLine::Around))
@@ -64,7 +64,7 @@ impl ImportScope {
6464
}
6565

6666
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
6868
match self
6969
.as_syntax_node()
7070
.children()
@@ -119,7 +119,7 @@ pub(crate) fn insert_use(
119119
}
120120

121121
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
123123
buf.push(make::tokens::whitespace(&" ".repeat(4 * ident_level)).into());
124124
}
125125
buf.push(use_item.syntax().clone().into());
@@ -530,8 +530,6 @@ fn main() {}",
530530

531531
#[test]
532532
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
535533
check_full(
536534
"foo::bar",
537535
r"#![allow(unused_imports)]",
@@ -543,8 +541,6 @@ use foo::bar;",
543541

544542
#[test]
545543
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
548544
check_full(
549545
"foo::bar",
550546
r"#![allow(unused_imports)]
@@ -647,6 +643,16 @@ use std::io;",
647643
)
648644
}
649645

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};
652+
use std::io;",
653+
)
654+
}
655+
650656
#[test]
651657
#[ignore] // FIXME: Support this
652658
fn split_out_merge() {

0 commit comments

Comments
 (0)