mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
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 <lukastw97@gmail.com>
This commit is contained in:
commit
2e33bf23c9
1 changed files with 34 additions and 1 deletions
|
@ -84,12 +84,12 @@ pub(crate) fn replace_qualified_name_with_use(
|
||||||
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
|
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
|
||||||
ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)),
|
ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)),
|
||||||
};
|
};
|
||||||
|
shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
|
||||||
// stick the found import in front of the to be replaced path
|
// stick the found import in front of the to be replaced path
|
||||||
let path = match path_to_qualifier.and_then(|it| mod_path_to_ast(&it).qualifier()) {
|
let path = match path_to_qualifier.and_then(|it| mod_path_to_ast(&it).qualifier()) {
|
||||||
Some(qualifier) => make::path_concat(qualifier, path),
|
Some(qualifier) => make::path_concat(qualifier, path),
|
||||||
None => path,
|
None => path,
|
||||||
};
|
};
|
||||||
shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
|
|
||||||
insert_use(&scope, path, &ctx.config.insert_use);
|
insert_use(&scope, path, &ctx.config.insert_use);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -356,6 +356,39 @@ mod bar {
|
||||||
fn main() {
|
fn main() {
|
||||||
Foo;
|
Foo;
|
||||||
}
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn replace_does_not_always_try_to_replace_by_full_item_path() {
|
||||||
|
check_assist(
|
||||||
|
replace_qualified_name_with_use,
|
||||||
|
r"
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
mod std {
|
||||||
|
pub mod mem {
|
||||||
|
pub fn drop<T>(_: T) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mem::drop$0(0);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
use std::mem::{self, drop};
|
||||||
|
|
||||||
|
mod std {
|
||||||
|
pub mod mem {
|
||||||
|
pub fn drop<T>(_: T) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
drop(0);
|
||||||
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue