mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-25 21:37:39 +00:00
Add infrastructure for visibility on syntax and hir_def level
This commit is contained in:
parent
97f01396ed
commit
069bf55cca
5 changed files with 163 additions and 2 deletions
|
|
@ -17,7 +17,9 @@ use crate::{
|
|||
|
||||
pub use self::{
|
||||
expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
||||
extensions::{FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind},
|
||||
extensions::{
|
||||
FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind, VisibilityKind,
|
||||
},
|
||||
generated::*,
|
||||
tokens::*,
|
||||
traits::*,
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue