aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-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.rs22
3 files changed, 21 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..905e8c90b 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 && line.trim_start().starts_with("# ") {
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 }
@@ -22,8 +26,20 @@ mod tests {
22 use super::*; 26 use super::*;
23 27
24 #[test] 28 #[test]
25 fn test_codeblock_adds_rust() { 29 fn test_format_docs_adds_rust() {
26 let comment = "```\nfn some_rust() {}\n```"; 30 let comment = "```\nfn some_rust() {}\n```";
27 assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```"); 31 assert_eq!(format_docs(comment), "```rust\nfn some_rust() {}\n```");
32 }
33
34 #[test]
35 fn test_format_docs_skips_comments_in_rust_block() {
36 let comment = "```rust\n # skip1\n# skip2\n#stay1\nstay2\n```";
37 assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```");
38 }
39
40 #[test]
41 fn test_format_docs_keeps_comments_outside_of_rust_block() {
42 let comment = " # stay1\n# stay2\n#stay3\nstay4";
43 assert_eq!(format_docs(comment), comment);
28 } 44 }
29} 45}