mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Hide comments in rust section of doc comments
This commit is contained in:
parent
359b3376b3
commit
1c11d7b1d8
3 changed files with 21 additions and 5 deletions
|
@ -171,7 +171,7 @@ impl Conv for ra_ide_api::Documentation {
|
||||||
fn conv(self) -> Documentation {
|
fn conv(self) -> Documentation {
|
||||||
Documentation::MarkupContent(MarkupContent {
|
Documentation::MarkupContent(MarkupContent {
|
||||||
kind: MarkupKind::Markdown,
|
kind: MarkupKind::Markdown,
|
||||||
value: crate::markdown::mark_fenced_blocks_as_rust(self.as_str()),
|
value: crate::markdown::format_docs(self.as_str()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -485,7 +485,7 @@ pub fn handle_hover(
|
||||||
let res = Hover {
|
let res = Hover {
|
||||||
contents: HoverContents::Markup(MarkupContent {
|
contents: HoverContents::Markup(MarkupContent {
|
||||||
kind: MarkupKind::Markdown,
|
kind: MarkupKind::Markdown,
|
||||||
value: info.info.to_markup(),
|
value: crate::markdown::format_docs(&info.info.to_markup()),
|
||||||
}),
|
}),
|
||||||
range: Some(range),
|
range: Some(range),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
pub(crate) fn mark_fenced_blocks_as_rust(src: &str) -> String {
|
pub(crate) fn format_docs(src: &str) -> String {
|
||||||
let mut processed_lines = Vec::new();
|
let mut processed_lines = Vec::new();
|
||||||
let mut in_code_block = false;
|
let mut in_code_block = false;
|
||||||
for line in src.lines() {
|
for line in src.lines() {
|
||||||
|
if in_code_block && line.trim_start().starts_with("# ") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if line.starts_with("```") {
|
if line.starts_with("```") {
|
||||||
in_code_block ^= true
|
in_code_block ^= true
|
||||||
}
|
}
|
||||||
|
@ -22,8 +26,20 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_codeblock_adds_rust() {
|
fn test_format_docs_adds_rust() {
|
||||||
let comment = "```\nfn some_rust() {}\n```";
|
let comment = "```\nfn some_rust() {}\n```";
|
||||||
assert_eq!(mark_fenced_blocks_as_rust(comment), "```rust\nfn some_rust() {}\n```");
|
assert_eq!(format_docs(comment), "```rust\nfn some_rust() {}\n```");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_docs_skips_comments_in_rust_block() {
|
||||||
|
let comment = "```rust\n # skip1\n# skip2\n#stay1\nstay2\n```";
|
||||||
|
assert_eq!(format_docs(comment), "```rust\n#stay1\nstay2\n```");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_docs_keeps_comments_outside_of_rust_block() {
|
||||||
|
let comment = " # stay1\n# stay2\n#stay3\nstay4";
|
||||||
|
assert_eq!(format_docs(comment), comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue