mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Merge #1478
1478: [WIP] Added resolve submodules with raw name r=matklad a=andreevlex #1211 Co-authored-by: Alexander Andreev <andreevlex.as@gmail.com>
This commit is contained in:
commit
4e8664d9d3
2 changed files with 39 additions and 2 deletions
|
@ -98,13 +98,15 @@ pub(crate) trait AsName {
|
|||
|
||||
impl AsName for ast::NameRef {
|
||||
fn as_name(&self) -> Name {
|
||||
Name::new(self.text().clone())
|
||||
let name = resolve_name(self.text());
|
||||
Name::new(name)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsName for ast::Name {
|
||||
fn as_name(&self) -> Name {
|
||||
Name::new(self.text().clone())
|
||||
let name = resolve_name(self.text());
|
||||
Name::new(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,3 +186,12 @@ impl AsName for KnownName {
|
|||
Name::new(s.into())
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_name(text: &SmolStr) -> SmolStr {
|
||||
let raw_start = "r#";
|
||||
if text.as_str().starts_with(raw_start) {
|
||||
SmolStr::new(&text[raw_start.len()..])
|
||||
} else {
|
||||
text.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -338,6 +338,32 @@ fn module_resolution_works_for_non_standard_filenames() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn module_resolution_works_for_raw_modules() {
|
||||
let map = def_map_with_crate_graph(
|
||||
"
|
||||
//- /library.rs
|
||||
mod r#async;
|
||||
use self::r#async::Bar;
|
||||
|
||||
//- /async.rs
|
||||
pub struct Bar;
|
||||
",
|
||||
crate_graph! {
|
||||
"library": ("/library.rs", []),
|
||||
},
|
||||
);
|
||||
|
||||
assert_snapshot_matches!(map, @r###"
|
||||
⋮crate
|
||||
⋮Bar: t v
|
||||
⋮async: t
|
||||
⋮
|
||||
⋮crate::async
|
||||
⋮Bar: t v
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn name_res_works_for_broken_modules() {
|
||||
covers!(name_res_works_for_broken_modules);
|
||||
|
|
Loading…
Reference in a new issue