extract_type_alias extracts generics correctly

This commit is contained in:
Lukas Wirth 2021-08-05 02:54:06 +02:00
parent 01413dd7d4
commit b6d574642d
2 changed files with 175 additions and 17 deletions

View file

@ -8,7 +8,10 @@ use parser::SyntaxKind;
use rowan::{GreenNodeData, GreenTokenData, WalkEvent};
use crate::{
ast::{self, support, AstChildren, AstNode, AstToken, AttrsOwner, NameOwner, SyntaxNode},
ast::{
self, support, AstChildren, AstNode, AstToken, AttrsOwner, GenericParamsOwner, NameOwner,
SyntaxNode,
},
NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
};
@ -593,6 +596,21 @@ impl ast::Variant {
}
}
impl ast::Item {
pub fn generic_param_list(&self) -> Option<ast::GenericParamList> {
match self {
ast::Item::Enum(it) => it.generic_param_list(),
ast::Item::Fn(it) => it.generic_param_list(),
ast::Item::Impl(it) => it.generic_param_list(),
ast::Item::Struct(it) => it.generic_param_list(),
ast::Item::Trait(it) => it.generic_param_list(),
ast::Item::TypeAlias(it) => it.generic_param_list(),
ast::Item::Union(it) => it.generic_param_list(),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FieldKind {
Name(ast::NameRef),