mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Check for rust doc code attributes like rustdoc does
This commit is contained in:
parent
8a959497b1
commit
2f62c0117a
5 changed files with 40 additions and 45 deletions
|
@ -1,19 +1,7 @@
|
|||
//! Transforms markdown
|
||||
use ide_db::helpers::rust_doc::is_rust_fence;
|
||||
|
||||
const RUSTDOC_FENCE: &str = "```";
|
||||
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC: &[&str] = &[
|
||||
"",
|
||||
"rust",
|
||||
"should_panic",
|
||||
"ignore",
|
||||
"no_run",
|
||||
"compile_fail",
|
||||
"allow_fail",
|
||||
"test_harness",
|
||||
"edition2015",
|
||||
"edition2018",
|
||||
"edition2021",
|
||||
];
|
||||
|
||||
pub(crate) fn format_docs(src: &str) -> String {
|
||||
let mut processed_lines = Vec::new();
|
||||
|
@ -29,8 +17,7 @@ pub(crate) fn format_docs(src: &str) -> String {
|
|||
in_code_block ^= true;
|
||||
|
||||
if in_code_block {
|
||||
is_rust =
|
||||
header.split(',').any(|sub| is_rust_specific_code_block_attribute(sub.trim()));
|
||||
is_rust = is_rust_fence(header);
|
||||
|
||||
if is_rust {
|
||||
line = "```rust";
|
||||
|
@ -43,13 +30,6 @@ pub(crate) fn format_docs(src: &str) -> String {
|
|||
processed_lines.join("\n")
|
||||
}
|
||||
|
||||
fn is_rust_specific_code_block_attribute(attr: &str) -> bool {
|
||||
if RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUST_SPECIFIC.contains(&attr) {
|
||||
return true;
|
||||
}
|
||||
attr.starts_with('E') && attr.len() == 5 && attr[1..].parse::<u32>().is_ok()
|
||||
}
|
||||
|
||||
fn code_line_ignored_by_rustdoc(line: &str) -> bool {
|
||||
let trimmed = line.trim();
|
||||
trimmed == "#" || trimmed.starts_with("# ") || trimmed.starts_with("#\t")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue