From 069bf55cca1e1be1f6cdd28b638f691e059858dc Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 24 Dec 2019 20:32:42 +0100 Subject: Add infrastructure for visibility on syntax and hir_def level --- crates/ra_syntax/src/ast/extensions.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'crates/ra_syntax/src/ast/extensions.rs') diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index baaef3023..d9666cdca 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -413,3 +413,32 @@ impl ast::TraitDef { self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) } } + +pub enum VisibilityKind { + In(ast::Path), + PubCrate, + PubSuper, + Pub, +} + +impl ast::Visibility { + pub fn kind(&self) -> VisibilityKind { + if let Some(path) = children(self).next() { + VisibilityKind::In(path) + } else if self.is_pub_crate() { + VisibilityKind::PubCrate + } else if self.is_pub_super() { + VisibilityKind::PubSuper + } else { + VisibilityKind::Pub + } + } + + fn is_pub_crate(&self) -> bool { + self.syntax().children_with_tokens().any(|it| it.kind() == T![crate]) + } + + fn is_pub_super(&self) -> bool { + self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) + } +} -- cgit v1.2.3