aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorEkaterina Babshukova <[email protected]>2019-10-16 14:49:35 +0100
committerEkaterina Babshukova <[email protected]>2019-10-22 21:47:31 +0100
commitb5a3ee93e24931c8bba628ddc7be4f098a19a326 (patch)
treeaaf6ecb7f04abfd3ba855d848777cd0fbb8307e1 /crates/ra_ide_api
parent55e1910d006da7961687928542c1167cc556a39f (diff)
support items that visible to the parent module
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/references.rs28
-rw-r--r--crates/ra_ide_api/src/references/classify.rs1
-rw-r--r--crates/ra_ide_api/src/references/search_scope.rs44
3 files changed, 68 insertions, 5 deletions
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 3d647d2cb..aadd52616 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -270,9 +270,8 @@ mod tests {
270 assert_eq!(refs.len(), 3); 270 assert_eq!(refs.len(), 3);
271 } 271 }
272 272
273
274 // `mod foo;` is not in the results because `foo` is an `ast::Name`. 273 // `mod foo;` is not in the results because `foo` is an `ast::Name`.
275 // So, there are two references: the first one is a definition of the `foo` module, 274 // So, there are two references: the first one is a definition of the `foo` module,
276 // which is the whole `foo.rs`, and the second one is in `use foo::Foo`. 275 // which is the whole `foo.rs`, and the second one is in `use foo::Foo`.
277 #[test] 276 #[test]
278 fn test_find_all_refs_decl_module() { 277 fn test_find_all_refs_decl_module() {
@@ -297,6 +296,31 @@ mod tests {
297 assert_eq!(refs.len(), 2); 296 assert_eq!(refs.len(), 2);
298 } 297 }
299 298
299 #[test]
300 fn test_find_all_refs_super_mod_vis() {
301 let code = r#"
302 //- /lib.rs
303 mod foo;
304
305 //- /foo.rs
306 mod some;
307 use some::Foo;
308
309 fn f() {
310 let i = Foo { n: 5 };
311 }
312
313 //- /foo/some.rs
314 pub(super) struct Foo<|> {
315 pub n: u32,
316 }
317 "#;
318
319 let (analysis, pos) = analysis_and_position(code);
320 let refs = analysis.find_all_refs(pos).unwrap().unwrap();
321 assert_eq!(refs.len(), 3);
322 }
323
300 fn get_all_refs(text: &str) -> ReferenceSearchResult { 324 fn get_all_refs(text: &str) -> ReferenceSearchResult {
301 let (analysis, position) = single_file_with_position(text); 325 let (analysis, position) = single_file_with_position(text);
302 analysis.find_all_refs(position).unwrap().unwrap() 326 analysis.find_all_refs(position).unwrap().unwrap()
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs
index ac9cf34eb..3beab9861 100644
--- a/crates/ra_ide_api/src/references/classify.rs
+++ b/crates/ra_ide_api/src/references/classify.rs
@@ -152,6 +152,7 @@ pub(crate) fn classify_name_ref(
152 AssocItem(item) => Some(from_assoc_item(db, item)), 152 AssocItem(item) => Some(from_assoc_item(db, item)),
153 LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat), 153 LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat),
154 LocalBinding(Either::B(par)) => { 154 LocalBinding(Either::B(par)) => {
155 // Not really supported
155 let kind = NameKind::SelfParam(par); 156 let kind = NameKind::SelfParam(par);
156 Some(NameDefinition { kind, container, visibility }) 157 Some(NameDefinition { kind, container, visibility })
157 } 158 }
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs
index d2c966b4f..8495a92a5 100644
--- a/crates/ra_ide_api/src/references/search_scope.rs
+++ b/crates/ra_ide_api/src/references/search_scope.rs
@@ -25,14 +25,53 @@ impl NameDefinition {
25 } 25 }
26 26
27 if let Some(ref vis) = self.visibility { 27 if let Some(ref vis) = self.visibility {
28 let vis = vis.syntax().to_string();
29
30 // FIXME: add "pub(in path)"
31
32 if vis.as_str() == "pub(super)" {
33 if let Some(parent_module) = self.container.parent(db) {
34 let mut files = HashSet::new();
35
36 let parent_src = parent_module.definition_source(db);
37 let file_id = parent_src.file_id.original_file(db);
38
39 match parent_src.ast {
40 ModuleSource::Module(m) => {
41 let range = Some(m.syntax().text_range());
42 files.insert((file_id, range));
43 }
44 ModuleSource::SourceFile(_) => {
45 files.insert((file_id, None));
46 files.extend(
47 parent_module
48 .children(db)
49 .map(|m| {
50 let src = m.definition_source(db);
51 (src.file_id.original_file(db), None)
52 })
53 .collect::<HashSet<_>>(),
54 );
55 }
56 }
57 return files;
58 } else {
59 let range = match module_src.ast {
60 ModuleSource::Module(m) => Some(m.syntax().text_range()),
61 ModuleSource::SourceFile(_) => None,
62 };
63 return [(file_id, range)].iter().cloned().collect();
64 }
65 }
66
28 let source_root_id = db.file_source_root(file_id); 67 let source_root_id = db.file_source_root(file_id);
29 let source_root = db.source_root(source_root_id); 68 let source_root = db.source_root(source_root_id);
30 let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<HashSet<_>>(); 69 let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<HashSet<_>>();
31 70
32 if vis.syntax().to_string().as_str() == "pub(crate)" { 71 if vis.as_str() == "pub(crate)" {
33 return files; 72 return files;
34 } 73 }
35 if vis.syntax().to_string().as_str() == "pub" { 74 if vis.as_str() == "pub" {
36 let krate = self.container.krate(db).unwrap(); 75 let krate = self.container.krate(db).unwrap();
37 let crate_graph = db.crate_graph(); 76 let crate_graph = db.crate_graph();
38 77
@@ -49,7 +88,6 @@ impl NameDefinition {
49 88
50 return files; 89 return files;
51 } 90 }
52 // FIXME: "pub(super)", "pub(in path)"
53 } 91 }
54 92
55 let range = match module_src.ast { 93 let range = match module_src.ast {