aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/references
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/src/references
parent55e1910d006da7961687928542c1167cc556a39f (diff)
support items that visible to the parent module
Diffstat (limited to 'crates/ra_ide_api/src/references')
-rw-r--r--crates/ra_ide_api/src/references/classify.rs1
-rw-r--r--crates/ra_ide_api/src/references/search_scope.rs44
2 files changed, 42 insertions, 3 deletions
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 {