Skip to content

Commit 2e33bf2

Browse files
bors[bot]Veykril
andauthored
Merge #11204
11204: fix: `replace_qualified_name_with_use` does not use full item path for replacements r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents ada51f2 + 2d33cdf commit 2e33bf2

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ pub(crate) fn replace_qualified_name_with_use(
8484
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
8585
ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)),
8686
};
87+
shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
8788
// stick the found import in front of the to be replaced path
8889
let path = match path_to_qualifier.and_then(|it| mod_path_to_ast(&it).qualifier()) {
8990
Some(qualifier) => make::path_concat(qualifier, path),
9091
None => path,
9192
};
92-
shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
9393
insert_use(&scope, path, &ctx.config.insert_use);
9494
},
9595
)
@@ -356,6 +356,39 @@ mod bar {
356356
fn main() {
357357
Foo;
358358
}
359+
",
360+
);
361+
}
362+
363+
#[test]
364+
fn replace_does_not_always_try_to_replace_by_full_item_path() {
365+
check_assist(
366+
replace_qualified_name_with_use,
367+
r"
368+
use std::mem;
369+
370+
mod std {
371+
pub mod mem {
372+
pub fn drop<T>(_: T) {}
373+
}
374+
}
375+
376+
fn main() {
377+
mem::drop$0(0);
378+
}
379+
",
380+
r"
381+
use std::mem::{self, drop};
382+
383+
mod std {
384+
pub mod mem {
385+
pub fn drop<T>(_: T) {}
386+
}
387+
}
388+
389+
fn main() {
390+
drop(0);
391+
}
359392
",
360393
);
361394
}

0 commit comments

Comments
 (0)