diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f275a4955..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 | } |
@@ -120,7 +122,7 @@ pub trait DocCommentsOwner: AstNode { | |||
120 | has_comments = true; | 122 | has_comments = true; |
121 | let prefix_len = comment.prefix().len(); | 123 | let prefix_len = comment.prefix().len(); |
122 | 124 | ||
123 | let line = comment.text().as_str(); | 125 | let line: &str = comment.text().as_str(); |
124 | 126 | ||
125 | // Determine if the prefix or prefix + 1 char is stripped | 127 | // Determine if the prefix or prefix + 1 char is stripped |
126 | let pos = | 128 | let pos = |
@@ -136,7 +138,10 @@ pub trait DocCommentsOwner: AstNode { | |||
136 | line.len() | 138 | line.len() |
137 | }; | 139 | }; |
138 | 140 | ||
139 | line[pos..end].trim_end().to_owned() | 141 | // Note that we do not trim the end of the line here |
142 | // since whitespace can have special meaning at the end | ||
143 | // of a line in markdown. | ||
144 | line[pos..end].to_owned() | ||
140 | }) | 145 | }) |
141 | .join("\n"); | 146 | .join("\n"); |
142 | 147 | ||