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/markdown.rs23
2 files changed, 8 insertions, 17 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 88d29b256..257492589 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::sanitize_markdown(self).into(), 174 value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()).into(),
175 }) 175 })
176 } 176 }
177} 177}
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/ra_lsp_server/src/markdown.rs
index f505755e8..e382eee90 100644
--- a/crates/ra_lsp_server/src/markdown.rs
+++ b/crates/ra_lsp_server/src/markdown.rs
@@ -1,26 +1,20 @@
1use ra_ide_api::Documentation; 1pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String {
2
3pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation {
4 let docs: String = docs.into();
5
6 // Massage markdown
7 let mut processed_lines = Vec::new(); 2 let mut processed_lines = Vec::new();
8 let mut in_code_block = false; 3 let mut in_code_block = false;
9 for line in docs.lines() { 4 for line in src.lines() {
10 if line.starts_with("```") { 5 if line.starts_with("```") {
11 in_code_block = !in_code_block; 6 in_code_block ^= true
12 } 7 }
13 8
14 let line = if in_code_block && line.starts_with("```") && !line.contains("rust") { 9 let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
15 "```rust".into() 10 "```rust"
16 } else { 11 } else {
17 line.to_string() 12 line
18 }; 13 };
19 14
20 processed_lines.push(line); 15 processed_lines.push(line);
21 } 16 }
22 17 processed_lines.join("\n")
23 Documentation::new(&processed_lines.join("\n"))
24} 18}
25 19
26#[cfg(test)] 20#[cfg(test)]
@@ -30,9 +24,6 @@ mod tests {
30 #[test] 24 #[test]
31 fn test_codeblock_adds_rust() { 25 fn test_codeblock_adds_rust() {
32 let comment = "```\nfn some_rust() {}\n```"; 26 let comment = "```\nfn some_rust() {}\n```";
33 assert_eq!( 27 assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```");
34 sanitize_markdown(Documentation::new(comment)).contents(),
35 "```rust\nfn some_rust() {}\n```"
36 );
37 } 28 }
38} 29}