From 1438f38eb63e5a79350fa6c877d9960ab90e183d Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 27 Oct 2019 16:56:25 -0400 Subject: Preserve whitespace at the end of doc comments Whitespace can have special meaning in markdown. For instance ending a line with three spaces will render a new line. Note that this behavior diverges from RLS. Fixes #1997 --- crates/ra_syntax/src/ast/traits.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f275a4955..76313684e 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -120,7 +120,7 @@ pub trait DocCommentsOwner: AstNode { has_comments = true; let prefix_len = comment.prefix().len(); - let line = comment.text().as_str(); + let line: &str = comment.text().as_str(); // Determine if the prefix or prefix + 1 char is stripped let pos = @@ -136,7 +136,10 @@ pub trait DocCommentsOwner: AstNode { line.len() }; - line[pos..end].trim_end().to_owned() + // Note that we do not trim the end of the line here + // since whitespace can have special meaning at the end + // of a line in markdown. + line[pos..end].to_owned() }) .join("\n"); -- cgit v1.2.3 From 78f93c8033d4803167536a070c2162b072e16055 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 16:08:59 -0400 Subject: traits => match_ast! --- crates/ra_syntax/src/ast/traits.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') 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; use crate::{ ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, + match_ast, syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, }; @@ -68,11 +69,12 @@ impl Iterator for ItemOrMacroIter { fn next(&mut self) -> Option { loop { let n = self.0.next()?; - if let Some(item) = ast::ModuleItem::cast(n.clone()) { - return Some(ItemOrMacro::Item(item)); - } - if let Some(call) = ast::MacroCall::cast(n) { - return Some(ItemOrMacro::Macro(call)); + match_ast! { + match n { + ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) }, + ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) }, + _ => {}, + } } } } -- cgit v1.2.3