From 2f62c0117a1d59a531f9c84fbdb2f70ff87d22e0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 19 Apr 2021 13:20:37 +0200 Subject: Check for rust doc code attributes like rustdoc does --- crates/ide/src/syntax_highlighting/inject.rs | 24 ++---------------------- crates/ide/src/syntax_highlighting/tests.rs | 2 +- 2 files changed, 3 insertions(+), 23 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 6b1037870..bc221d599 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -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::().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; } diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 933cfa6f3..17cc6334b 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -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] -- cgit v1.2.3