mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +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
|
@ -4,7 +4,7 @@ use std::mem;
|
|||
|
||||
use either::Either;
|
||||
use hir::{InFile, Semantics};
|
||||
use ide_db::{call_info::ActiveParameter, SymbolKind};
|
||||
use ide_db::{call_info::ActiveParameter, helpers::rust_doc::is_rust_fence, SymbolKind};
|
||||
use syntax::{
|
||||
ast::{self, AstNode},
|
||||
AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
||||
|
@ -78,26 +78,6 @@ pub(super) fn ra_fixture(
|
|||
}
|
||||
|
||||
const RUSTDOC_FENCE: &'static str = "```";
|
||||
const RUSTDOC_FENCE_TOKENS: &[&'static str] = &[
|
||||
"",
|
||||
"rust",
|
||||
"should_panic",
|
||||
"ignore",
|
||||
"no_run",
|
||||
"compile_fail",
|
||||
"allow_fail",
|
||||
"test_harness",
|
||||
"edition2015",
|
||||
"edition2018",
|
||||
"edition2021",
|
||||
];
|
||||
|
||||
fn is_rustdoc_fence_token(token: &str) -> bool {
|
||||
if RUSTDOC_FENCE_TOKENS.contains(&token) {
|
||||
return true;
|
||||
}
|
||||
token.starts_with('E') && token.len() == 5 && token[1..].parse::<u32>().is_ok()
|
||||
}
|
||||
|
||||
/// Injection of syntax highlighting of doctests.
|
||||
pub(super) fn doc_comment(
|
||||
|
@ -183,7 +163,7 @@ pub(super) fn doc_comment(
|
|||
is_codeblock = !is_codeblock;
|
||||
// Check whether code is rust by inspecting fence guards
|
||||
let guards = &line[idx + RUSTDOC_FENCE.len()..];
|
||||
let is_rust = guards.split(',').any(|sub| is_rustdoc_fence_token(sub.trim()));
|
||||
let is_rust = is_rust_fence(guards);
|
||||
is_doctest = is_codeblock && is_rust;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ fn benchmark_syntax_highlighting_parser() {
|
|||
.filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
|
||||
.count()
|
||||
};
|
||||
assert_eq!(hash, 1629);
|
||||
assert_eq!(hash, 1632);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue