From b5a3ee93e24931c8bba628ddc7be4f098a19a326 Mon Sep 17 00:00:00 2001 From: Ekaterina Babshukova Date: Wed, 16 Oct 2019 16:49:35 +0300 Subject: support items that visible to the parent module --- crates/ra_ide_api/src/references/classify.rs | 1 + crates/ra_ide_api/src/references/search_scope.rs | 44 ++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide_api/src/references') 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( AssocItem(item) => Some(from_assoc_item(db, item)), LocalBinding(Either::A(pat)) => from_pat(db, file_id, pat), LocalBinding(Either::B(par)) => { + // Not really supported let kind = NameKind::SelfParam(par); Some(NameDefinition { kind, container, visibility }) } 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 { } if let Some(ref vis) = self.visibility { + let vis = vis.syntax().to_string(); + + // FIXME: add "pub(in path)" + + if vis.as_str() == "pub(super)" { + if let Some(parent_module) = self.container.parent(db) { + let mut files = HashSet::new(); + + let parent_src = parent_module.definition_source(db); + let file_id = parent_src.file_id.original_file(db); + + match parent_src.ast { + ModuleSource::Module(m) => { + let range = Some(m.syntax().text_range()); + files.insert((file_id, range)); + } + ModuleSource::SourceFile(_) => { + files.insert((file_id, None)); + files.extend( + parent_module + .children(db) + .map(|m| { + let src = m.definition_source(db); + (src.file_id.original_file(db), None) + }) + .collect::>(), + ); + } + } + return files; + } else { + let range = match module_src.ast { + ModuleSource::Module(m) => Some(m.syntax().text_range()), + ModuleSource::SourceFile(_) => None, + }; + return [(file_id, range)].iter().cloned().collect(); + } + } + let source_root_id = db.file_source_root(file_id); let source_root = db.source_root(source_root_id); let mut files = source_root.walk().map(|id| (id.into(), None)).collect::>(); - if vis.syntax().to_string().as_str() == "pub(crate)" { + if vis.as_str() == "pub(crate)" { return files; } - if vis.syntax().to_string().as_str() == "pub" { + if vis.as_str() == "pub" { let krate = self.container.krate(db).unwrap(); let crate_graph = db.crate_graph(); @@ -49,7 +88,6 @@ impl NameDefinition { return files; } - // FIXME: "pub(super)", "pub(in path)" } let range = match module_src.ast { -- cgit v1.2.3