aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-31 13:09:22 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-31 13:09:22 +0100
commit1af7738c28d4bb15254612574784a762b2c1e2e9 (patch)
tree974244f919ebde8816be1bc7e8c6c226e4e449cf
parent457fdf90c8110f74fb9e917fac825a60915c22a8 (diff)
parentfacc7a35a5ce5cc8be0d03bedd4e00959a03f851 (diff)
Merge #1627
1627: Hide ignored lines in rustdoc r=kjeremy a=rizakrko This fixes #1620. Co-authored-by: Roman Stoliar <[email protected]>
-rw-r--r--crates/ra_lsp_server/src/conv.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs2
-rw-r--r--crates/ra_lsp_server/src/markdown.rs28
3 files changed, 27 insertions, 5 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 6b3be444f..59c5e1582 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -171,7 +171,7 @@ impl Conv for ra_ide_api::Documentation {
171 fn conv(self) -> Documentation { 171 fn conv(self) -> Documentation {
172 Documentation::MarkupContent(MarkupContent { 172 Documentation::MarkupContent(MarkupContent {
173 kind: MarkupKind::Markdown, 173 kind: MarkupKind::Markdown,
174 value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()), 174 value: crate::markdown::format_docs(self.as_str()),
175 }) 175 })
176 } 176 }
177} 177}
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 9006aa316..ee48d0cb8 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -485,7 +485,7 @@ pub fn handle_hover(
485 let res = Hover { 485 let res = Hover {
486 contents: HoverContents::Markup(MarkupContent { 486 contents: HoverContents::Markup(MarkupContent {
487 kind: MarkupKind::Markdown, 487 kind: MarkupKind::Markdown,
488 value: info.info.to_markup(), 488 value: crate::markdown::format_docs(&info.info.to_markup()),
489 }), 489 }),
490 range: Some(range), 490 range: Some(range),
491 }; 491 };
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs
index e382eee90..53cf24482 100644
--- a/crates/ra_lsp_server/src/markdown.rs
+++ b/crates/ra_lsp_server/src/markdown.rs
@@ -1,7 +1,11 @@
1pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String { 1pub(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 && code_line_ignored_by_rustdoc(line) {
6 continue;
7 }
8
5 if line.starts_with("```") { 9 if line.starts_with("```") {
6 in_code_block ^= true 10 in_code_block ^= true
7 } 11 }
@@ -17,13 +21,31 @@ pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String {
17 processed_lines.join("\n") 21 processed_lines.join("\n")
18} 22}
19 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
20#[cfg(test)] 29#[cfg(test)]
21mod tests { 30mod tests {
22 use super::*; 31 use super::*;
23 32
24 #[test] 33 #[test]
25 fn test_codeblock_adds_rust() { 34 fn test_format_docs_adds_rust() {
26 let comment = "```\nfn some_rust() {}\n```"; 35 let comment = "```\nfn some_rust() {}\n```";
27 assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```"); 36 assert_eq!(format_docs(comment), "```rust\nfn some_rust() {}\n```");
37 }
38
39 #[test]
40 fn test_format_docs_skips_comments_in_rust_block() {
41 let comment =
42 "```rust\n # skip1\n# skip2\n#stay1\nstay2\n#\n #\n # \n #\tskip3\n\t#\t\n```";
43 assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```");
44 }
45
46 #[test]
47 fn test_format_docs_keeps_comments_outside_of_rust_block() {
48 let comment = " # stay1\n# stay2\n#stay3\nstay4\n#\n #\n # \n #\tstay5\n\t#\t";
49 assert_eq!(format_docs(comment), comment);
28 } 50 }
29} 51}