mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-20 02:20:21 +00:00
Wrap remaining self/super/crate in Name{Ref}
This commit is contained in:
parent
8a869e870a
commit
98718e0544
28 changed files with 237 additions and 169 deletions
|
@ -11,6 +11,7 @@ pub struct Name {
|
|||
}
|
||||
impl Name {
|
||||
pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
|
||||
pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NameRef {
|
||||
|
@ -238,7 +239,6 @@ impl ExternCrate {
|
|||
pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
|
||||
pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
|
||||
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
|
||||
pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
|
||||
pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
|
||||
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
|
||||
}
|
||||
|
@ -406,9 +406,6 @@ pub struct Visibility {
|
|||
impl Visibility {
|
||||
pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
|
||||
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
|
||||
pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
|
||||
pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
|
||||
pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
|
||||
pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
|
||||
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
|
||||
pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
|
||||
|
@ -492,11 +489,11 @@ pub struct SelfParam {
|
|||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl ast::AttrsOwner for SelfParam {}
|
||||
impl ast::NameOwner for SelfParam {}
|
||||
impl SelfParam {
|
||||
pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
|
||||
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
|
||||
pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
|
||||
pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
|
||||
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
|
||||
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
|
||||
}
|
||||
|
|
|
@ -198,6 +198,13 @@ impl ast::Path {
|
|||
pub fn parent_path(&self) -> Option<ast::Path> {
|
||||
self.syntax().parent().and_then(ast::Path::cast)
|
||||
}
|
||||
|
||||
pub fn as_single_segment(&self) -> Option<ast::PathSegment> {
|
||||
match self.qualifier() {
|
||||
Some(_) => None,
|
||||
None => self.segment(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::UseTreeList {
|
||||
|
@ -448,16 +455,22 @@ pub enum VisibilityKind {
|
|||
|
||||
impl ast::Visibility {
|
||||
pub fn kind(&self) -> VisibilityKind {
|
||||
if let Some(path) = support::children(self.syntax()).next() {
|
||||
VisibilityKind::In(path)
|
||||
} else if self.crate_token().is_some() {
|
||||
VisibilityKind::PubCrate
|
||||
} else if self.super_token().is_some() {
|
||||
VisibilityKind::PubSuper
|
||||
} else if self.self_token().is_some() {
|
||||
VisibilityKind::PubSelf
|
||||
} else {
|
||||
VisibilityKind::Pub
|
||||
match self.path() {
|
||||
Some(path) => {
|
||||
if let Some(segment) =
|
||||
path.as_single_segment().filter(|it| it.coloncolon_token().is_none())
|
||||
{
|
||||
if segment.crate_token().is_some() {
|
||||
return VisibilityKind::PubCrate;
|
||||
} else if segment.super_token().is_some() {
|
||||
return VisibilityKind::PubSuper;
|
||||
} else if segment.self_token().is_some() {
|
||||
return VisibilityKind::PubSelf;
|
||||
}
|
||||
}
|
||||
VisibilityKind::In(path)
|
||||
}
|
||||
None => VisibilityKind::Pub,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue