aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorRoman Stoliar <[email protected]>2019-07-30 19:25:51 +0100
committerRoman Stoliar <[email protected]>2019-07-30 19:25:51 +0100
commitfacc7a35a5ce5cc8be0d03bedd4e00959a03f851 (patch)
treef3a9bd21a2fd6265fd1b1c6f3a2c4e835bcbf044 /crates/ra_lsp_server
parent1c11d7b1d87501687cda5efae9188e883ea3b92c (diff)
Fixed review comments
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/markdown.rs12
1 files changed, 9 insertions, 3 deletions
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 {
2 let mut processed_lines = Vec::new(); 2 let mut processed_lines = Vec::new();
3 let mut in_code_block = false; 3 let mut in_code_block = false;
4 for line in src.lines() { 4 for line in src.lines() {
5 if in_code_block && line.trim_start().starts_with("# ") { 5 if in_code_block && code_line_ignored_by_rustdoc(line) {
6 continue; 6 continue;
7 } 7 }
8 8
@@ -21,6 +21,11 @@ pub(crate) fn format_docs(src: &str) -> String {
21 processed_lines.join("\n") 21 processed_lines.join("\n")
22} 22}
23 23
24fn code_line_ignored_by_rustdoc(line: &str) -> bool {
25 let trimmed = line.trim();
26 trimmed == "#" || trimmed.starts_with("# ") || trimmed.starts_with("#\t")
27}
28
24#[cfg(test)] 29#[cfg(test)]
25mod tests { 30mod tests {
26 use super::*; 31 use super::*;
@@ -33,13 +38,14 @@ mod tests {
33 38
34 #[test] 39 #[test]
35 fn test_format_docs_skips_comments_in_rust_block() { 40 fn test_format_docs_skips_comments_in_rust_block() {
36 let comment = "```rust\n # skip1\n# skip2\n#stay1\nstay2\n```"; 41 let comment =
42 "```rust\n # skip1\n# skip2\n#stay1\nstay2\n#\n #\n # \n #\tskip3\n\t#\t\n```";
37 assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```"); 43 assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```");
38 } 44 }
39 45
40 #[test] 46 #[test]
41 fn test_format_docs_keeps_comments_outside_of_rust_block() { 47 fn test_format_docs_keeps_comments_outside_of_rust_block() {
42 let comment = " # stay1\n# stay2\n#stay3\nstay4"; 48 let comment = " # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t";
43 assert_eq!(format_docs(comment), comment); 49 assert_eq!(format_docs(comment), comment);
44 } 50 }
45} 51}