mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Add derive handles cursor
This commit is contained in:
parent
7094291573
commit
a5515d9d6f
5 changed files with 51 additions and 20 deletions
|
@ -339,6 +339,7 @@ impl<R: TreeRoot> AstNode<R> for NominalDef<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> ast::AttrsOwner<R> for NominalDef<R> {}
|
||||
impl<R: TreeRoot> NominalDef<R> {}
|
||||
|
||||
// ParenType
|
||||
|
|
|
@ -52,19 +52,31 @@ impl<R: TreeRoot> File<R> {
|
|||
impl<R: TreeRoot> FnDef<R> {
|
||||
pub fn has_atom_attr(&self, atom: &str) -> bool {
|
||||
self.attrs()
|
||||
.filter_map(|x| x.value())
|
||||
.filter_map(|x| as_atom(x))
|
||||
.filter_map(|x| x.as_atom())
|
||||
.any(|x| x == atom)
|
||||
}
|
||||
}
|
||||
|
||||
fn as_atom<R: TreeRoot>(tt: TokenTree<R>) -> Option<SmolStr> {
|
||||
let syntax = tt.syntax_ref();
|
||||
let (_bra, attr, _ket) = syntax.children().collect_tuple()?;
|
||||
if attr.kind() == IDENT {
|
||||
Some(attr.leaf_text().unwrap())
|
||||
} else {
|
||||
None
|
||||
impl<R: TreeRoot> Attr<R> {
|
||||
pub fn as_atom(&self) -> Option<SmolStr> {
|
||||
let tt = self.value()?;
|
||||
let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?;
|
||||
if attr.kind() == IDENT {
|
||||
Some(attr.leaf_text().unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_call(&self) -> Option<(SmolStr, TokenTree<R>)> {
|
||||
let tt = self.value()?;
|
||||
let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?;
|
||||
let args = TokenTree::cast(args)?;
|
||||
if attr.kind() == IDENT {
|
||||
Some((attr.leaf_text().unwrap(), args))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -272,6 +272,9 @@ Grammar(
|
|||
"DynTraitType",
|
||||
]),
|
||||
|
||||
"NominalDef": ( enum: ["StructDef", "EnumDef"]),
|
||||
"NominalDef": (
|
||||
enum: ["StructDef", "EnumDef"],
|
||||
traits: [ "AttrsOwner" ],
|
||||
),
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue