diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/text_tree_sink.rs | 2 |
3 files changed, 22 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index a12da5be2..1ec9881b9 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -113,6 +113,20 @@ fn test_doc_comment_of_items() { | |||
113 | } | 113 | } |
114 | 114 | ||
115 | #[test] | 115 | #[test] |
116 | fn test_doc_comment_of_statics() { | ||
117 | let file = SourceFile::parse( | ||
118 | r#" | ||
119 | /// Number of levels | ||
120 | static LEVELS: i32 = 0; | ||
121 | "#, | ||
122 | ) | ||
123 | .ok() | ||
124 | .unwrap(); | ||
125 | let st = file.syntax().descendants().find_map(StaticDef::cast).unwrap(); | ||
126 | assert_eq!("Number of levels", st.doc_comment_text().unwrap()); | ||
127 | } | ||
128 | |||
129 | #[test] | ||
116 | fn test_doc_comment_preserves_indents() { | 130 | fn test_doc_comment_preserves_indents() { |
117 | let file = SourceFile::parse( | 131 | let file = SourceFile::parse( |
118 | r#" | 132 | r#" |
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 76313684e..c2b005886 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs | |||
@@ -6,6 +6,7 @@ use itertools::Itertools; | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, | 8 | ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, |
9 | match_ast, | ||
9 | syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, | 10 | syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, |
10 | }; | 11 | }; |
11 | 12 | ||
@@ -68,11 +69,12 @@ impl Iterator for ItemOrMacroIter { | |||
68 | fn next(&mut self) -> Option<ItemOrMacro> { | 69 | fn next(&mut self) -> Option<ItemOrMacro> { |
69 | loop { | 70 | loop { |
70 | let n = self.0.next()?; | 71 | let n = self.0.next()?; |
71 | if let Some(item) = ast::ModuleItem::cast(n.clone()) { | 72 | match_ast! { |
72 | return Some(ItemOrMacro::Item(item)); | 73 | match n { |
73 | } | 74 | ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) }, |
74 | if let Some(call) = ast::MacroCall::cast(n) { | 75 | ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) }, |
75 | return Some(ItemOrMacro::Macro(call)); | 76 | _ => {}, |
77 | } | ||
76 | } | 78 | } |
77 | } | 79 | } |
78 | } | 80 | } |
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index 142164316..c36756d6c 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs | |||
@@ -147,7 +147,7 @@ fn n_attached_trivias<'a>( | |||
147 | ) -> usize { | 147 | ) -> usize { |
148 | match kind { | 148 | match kind { |
149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF | 149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF |
150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF => { | 150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { |
151 | let mut res = 0; | 151 | let mut res = 0; |
152 | for (i, (kind, text)) in trivias.enumerate() { | 152 | for (i, (kind, text)) in trivias.enumerate() { |
153 | match kind { | 153 | match kind { |