From facc7a35a5ce5cc8be0d03bedd4e00959a03f851 Mon Sep 17 00:00:00 2001 From: Roman Stoliar Date: Tue, 30 Jul 2019 21:25:51 +0300 Subject: Fixed review comments --- crates/ra_lsp_server/src/markdown.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs index 905e8c90b..53cf24482 100644 --- a/crates/ra_lsp_server/src/markdown.rs +++ b/crates/ra_lsp_server/src/markdown.rs @@ -2,7 +2,7 @@ pub(crate) fn format_docs(src: &str) -> String { let mut processed_lines = Vec::new(); let mut in_code_block = false; for line in src.lines() { - if in_code_block && line.trim_start().starts_with("# ") { + if in_code_block && code_line_ignored_by_rustdoc(line) { continue; } @@ -21,6 +21,11 @@ pub(crate) fn format_docs(src: &str) -> String { processed_lines.join("\n") } +fn code_line_ignored_by_rustdoc(line: &str) -> bool { + let trimmed = line.trim(); + trimmed == "#" || trimmed.starts_with("# ") || trimmed.starts_with("#\t") +} + #[cfg(test)] mod tests { use super::*; @@ -33,13 +38,14 @@ mod tests { #[test] fn test_format_docs_skips_comments_in_rust_block() { - let comment = "```rust\n # skip1\n# skip2\n#stay1\nstay2\n```"; + let comment = + "```rust\n # skip1\n# skip2\n#stay1\nstay2\n#\n #\n # \n #\tskip3\n\t#\t\n```"; assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```"); } #[test] fn test_format_docs_keeps_comments_outside_of_rust_block() { - let comment = " # stay1\n# stay2\n#stay3\nstay4"; + let comment = " # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t"; assert_eq!(format_docs(comment), comment); } } -- cgit v1.2.3