From d65dc40348afc90c812b4d392f8e085eca78fc17 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 31 Jul 2019 11:43:00 -0400 Subject: Removes `*/` in block doc comments --- crates/ra_syntax/src/ast/traits.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 6ed1b5213..0c193e019 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -115,7 +115,7 @@ pub trait DocCommentsOwner: AstNode { } /// Returns the textual content of a doc comment block as a single string. - /// That is, strips leading `///` (+ optional 1 character of whitespace) + /// That is, strips leading `///` or trailing `*/` (+ optional 1 character of whitespace in either direction) /// and joins lines. fn doc_comment_text(&self) -> Option { let mut has_comments = false; @@ -136,7 +136,18 @@ pub trait DocCommentsOwner: AstNode { prefix_len }; - line[pos..].to_owned() + let end = if comment.kind().shape.is_block() && line.ends_with("*/") { + // FIXME: Use `nth_back` here once stable + if line.chars().rev().nth(2).map(|c| c.is_whitespace()).unwrap_or(false) { + line.len() - 3 + } else { + line.len() - 2 + } + } else { + line.len() + }; + + line[pos..end].to_owned() }) .join("\n"); -- cgit v1.2.3