diff options
Diffstat (limited to 'crates/syntax/src/ast/token_ext.rs')
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 977eb8181..6c242d126 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -33,23 +33,20 @@ impl ast::Comment { | |||
33 | prefix | 33 | prefix |
34 | } | 34 | } |
35 | 35 | ||
36 | /// Returns the textual content of a doc comment block as a single string. | 36 | /// Returns the textual content of a doc comment node as a single string with prefix and suffix |
37 | /// That is, strips leading `///` (+ optional 1 character of whitespace), | 37 | /// removed. |
38 | /// trailing `*/`, trailing whitespace and then joins the lines. | ||
39 | pub fn doc_comment(&self) -> Option<&str> { | 38 | pub fn doc_comment(&self) -> Option<&str> { |
40 | let kind = self.kind(); | 39 | let kind = self.kind(); |
41 | match kind { | 40 | match kind { |
42 | CommentKind { shape, doc: Some(_) } => { | 41 | CommentKind { shape, doc: Some(_) } => { |
43 | let prefix = kind.prefix(); | 42 | let prefix = kind.prefix(); |
44 | let text = &self.text()[prefix.len()..]; | 43 | let text = &self.text()[prefix.len()..]; |
45 | let ws = text.chars().next().filter(|c| c.is_whitespace()); | 44 | let text = if shape == CommentShape::Block { |
46 | let text = ws.map_or(text, |ws| &text[ws.len_utf8()..]); | 45 | text.strip_suffix("*/").unwrap_or(text) |
47 | match shape { | 46 | } else { |
48 | CommentShape::Block if text.ends_with("*/") => { | 47 | text |
49 | Some(&text[..text.len() - "*/".len()]) | 48 | }; |
50 | } | 49 | Some(text) |
51 | _ => Some(text), | ||
52 | } | ||
53 | } | 50 | } |
54 | _ => None, | 51 | _ => None, |
55 | } | 52 | } |