aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAlexander Andreev <[email protected]>2019-07-03 20:01:41 +0100
committerAlexander Andreev <[email protected]>2019-07-03 20:01:41 +0100
commit02e9e46ed6443f053d2c22335ff57f98d5f64f05 (patch)
tree9fda20ca35f6193e9ebcb05aa0d01b8b3e19e94b /crates/ra_hir/src
parent018bf3d7b1cdc070aa1a0926df0840f1cf9a03b9 (diff)
Move resolve raw name in name.rs
Added test for check module resolution with raw name
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/name.rs15
-rw-r--r--crates/ra_hir/src/nameres/collector.rs9
-rw-r--r--crates/ra_hir/src/nameres/tests.rs27
3 files changed, 40 insertions, 11 deletions
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs
index ba17958eb..0bb7cae99 100644
--- a/crates/ra_hir/src/name.rs
+++ b/crates/ra_hir/src/name.rs
@@ -98,13 +98,15 @@ pub(crate) trait AsName {
98 98
99impl AsName for ast::NameRef { 99impl AsName for ast::NameRef {
100 fn as_name(&self) -> Name { 100 fn as_name(&self) -> Name {
101 Name::new(self.text().clone()) 101 let name = resolve_name(self.text().clone());
102 Name::new(name)
102 } 103 }
103} 104}
104 105
105impl AsName for ast::Name { 106impl AsName for ast::Name {
106 fn as_name(&self) -> Name { 107 fn as_name(&self) -> Name {
107 Name::new(self.text().clone()) 108 let name = resolve_name(self.text().clone());
109 Name::new(name)
108 } 110 }
109} 111}
110 112
@@ -184,3 +186,12 @@ impl AsName for KnownName {
184 Name::new(s.into()) 186 Name::new(s.into())
185 } 187 }
186} 188}
189
190fn resolve_name(text: SmolStr) -> SmolStr {
191 let raw_start = "r#";
192 if text.as_str().starts_with(raw_start) {
193 SmolStr::new(&text[raw_start.len()..])
194 } else {
195 text
196 }
197}
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index e11198e02..ef4d1ed70 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -643,7 +643,6 @@ fn resolve_submodule(
643 let mod_name = path.file_stem().unwrap_or("unknown"); 643 let mod_name = path.file_stem().unwrap_or("unknown");
644 let is_dir_owner = is_root || mod_name == "mod"; 644 let is_dir_owner = is_root || mod_name == "mod";
645 645
646 let name = resolve_mod_name(name.to_string());
647 let file_mod = dir_path.join(format!("{}.rs", name)); 646 let file_mod = dir_path.join(format!("{}.rs", name));
648 let dir_mod = dir_path.join(format!("{}/mod.rs", name)); 647 let dir_mod = dir_path.join(format!("{}/mod.rs", name));
649 let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name)); 648 let file_dir_mod = dir_path.join(format!("{}/{}.rs", mod_name, name));
@@ -663,14 +662,6 @@ fn resolve_submodule(
663 } 662 }
664} 663}
665 664
666fn resolve_mod_name(name: String) -> String {
667 if name.starts_with("r#") {
668 name.replace("r#", "")
669 } else {
670 name
671 }
672}
673
674#[cfg(test)] 665#[cfg(test)]
675mod tests { 666mod tests {
676 use ra_db::SourceDatabase; 667 use ra_db::SourceDatabase;
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index adac814d9..78332ce7c 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -339,6 +339,33 @@ fn module_resolution_works_for_non_standard_filenames() {
339} 339}
340 340
341#[test] 341#[test]
342fn module_resolution_works_for_raw_modules() {
343 let map = def_map_with_crate_graph(
344 "
345 //- /library.rs
346 mod r#async;
347 use self::r#async::Bar;
348
349 //- /async.rs
350 pub struct Bar;
351 ",
352 crate_graph! {
353 "library": ("/library.rs", []),
354 },
355 );
356
357 assert_snapshot_matches!(map, @r###"
358 ⋮crate
359 ⋮Bar: t v
360 ⋮async: t
361
362 ⋮crate::async
363 ⋮Bar: t v
364 "###);
365
366}
367
368#[test]
342fn name_res_works_for_broken_modules() { 369fn name_res_works_for_broken_modules() {
343 covers!(name_res_works_for_broken_modules); 370 covers!(name_res_works_for_broken_modules);
344 let map = def_map( 371 let map = def_map(