diff options
author | Aleksey Kladov <[email protected]> | 2019-05-20 23:04:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-05-20 23:15:56 +0100 |
commit | 765f93b8d851e5e853c844c8a279e73b4b7d965c (patch) | |
tree | ca8a3a7d60bca8e807a6597e4ec734953b4851d2 /crates | |
parent | 4ca8331933033b4cb8252c3056020bc4bfa2d78f (diff) |
add is_union to structs AST
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index f030e0df8..e4c99784c 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -3,7 +3,12 @@ | |||
3 | 3 | ||
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | 5 | ||
6 | use crate::{SmolStr, SyntaxToken, ast::{self, AstNode, children, child_opt}, SyntaxKind::*, SyntaxElement, T}; | 6 | use crate::{ |
7 | SmolStr, SyntaxToken, | ||
8 | ast::{self, AstNode, children, child_opt}, | ||
9 | SyntaxKind::*, | ||
10 | SyntaxElement, T, | ||
11 | }; | ||
7 | use ra_parser::SyntaxKind; | 12 | use ra_parser::SyntaxKind; |
8 | 13 | ||
9 | impl ast::Name { | 14 | impl ast::Name { |
@@ -196,6 +201,17 @@ impl StructKind<'_> { | |||
196 | } | 201 | } |
197 | 202 | ||
198 | impl ast::StructDef { | 203 | impl ast::StructDef { |
204 | pub fn is_union(&self) -> bool { | ||
205 | for child in self.syntax().children_with_tokens() { | ||
206 | match child.kind() { | ||
207 | T![struct] => return false, | ||
208 | T![union] => return true, | ||
209 | _ => (), | ||
210 | } | ||
211 | } | ||
212 | false | ||
213 | } | ||
214 | |||
199 | pub fn kind(&self) -> StructKind { | 215 | pub fn kind(&self) -> StructKind { |
200 | StructKind::from_node(self) | 216 | StructKind::from_node(self) |
201 | } | 217 | } |