From 33026c654e3a667e25ea27004c22be138ed83d33 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jun 2019 14:16:05 +0300 Subject: make Docs handing more ideomatic --- crates/ra_lsp_server/src/conv.rs | 2 +- crates/ra_lsp_server/src/markdown.rs | 23 +++++++---------------- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'crates/ra_lsp_server/src') 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 { fn conv(self) -> Documentation { Documentation::MarkupContent(MarkupContent { kind: MarkupKind::Markdown, - value: crate::markdown::sanitize_markdown(self).into(), + value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()).into(), }) } } 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 @@ -use ra_ide_api::Documentation; - -pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation { - let docs: String = docs.into(); - - // Massage markdown +pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String { let mut processed_lines = Vec::new(); let mut in_code_block = false; - for line in docs.lines() { + for line in src.lines() { if line.starts_with("```") { - in_code_block = !in_code_block; + in_code_block ^= true } let line = if in_code_block && line.starts_with("```") && !line.contains("rust") { - "```rust".into() + "```rust" } else { - line.to_string() + line }; processed_lines.push(line); } - - Documentation::new(&processed_lines.join("\n")) + processed_lines.join("\n") } #[cfg(test)] @@ -30,9 +24,6 @@ mod tests { #[test] fn test_codeblock_adds_rust() { let comment = "```\nfn some_rust() {}\n```"; - assert_eq!( - sanitize_markdown(Documentation::new(comment)).contents(), - "```rust\nfn some_rust() {}\n```" - ); + assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```"); } } -- cgit v1.2.3