mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Pass Documentation up to LSP and add "rust" to our codeblocks there
This commit is contained in:
parent
48d2acb297
commit
b88ba007cc
8 changed files with 103 additions and 89 deletions
38
crates/ra_lsp_server/src/markdown.rs
Normal file
38
crates/ra_lsp_server/src/markdown.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use ra_ide_api::Documentation;
|
||||
|
||||
pub(crate) fn sanitize_markdown(docs: Documentation) -> Documentation {
|
||||
let docs: String = docs.into();
|
||||
|
||||
// Massage markdown
|
||||
let mut processed_lines = Vec::new();
|
||||
let mut in_code_block = false;
|
||||
for line in docs.lines() {
|
||||
if line.starts_with("```") {
|
||||
in_code_block = !in_code_block;
|
||||
}
|
||||
|
||||
let line = if in_code_block && line.starts_with("```") && !line.contains("rust") {
|
||||
"```rust".into()
|
||||
} else {
|
||||
line.to_string()
|
||||
};
|
||||
|
||||
processed_lines.push(line);
|
||||
}
|
||||
|
||||
Documentation::new(&processed_lines.join("\n"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[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```"
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue