From a951108173349f9ff0b9936ec2af8881fd92fc98 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Wed, 17 Jun 2020 09:33:21 -0400 Subject: Ensure all existing doctest code highlights have documentation modifier --- crates/ra_ide/src/snapshots/highlight_doctest.html | 26 +++++++++++----------- crates/ra_ide/src/syntax_highlighting.rs | 8 +++---- crates/ra_ide/src/syntax_highlighting/injection.rs | 9 ++++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html index f1e007b09..106c93077 100644 --- a/crates/ra_ide/src/snapshots/highlight_doctest.html +++ b/crates/ra_ide/src/snapshots/highlight_doctest.html @@ -43,8 +43,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// # Examples /// /// ``` - /// # #![allow(unused_mut)] - /// let mut foo: Foo = Foo::new(); + /// # #![allow(unused_mut)] + /// let mut foo: Foo = Foo::new(); /// ``` pub const fn new() -> Foo { Foo { bar: true } @@ -55,26 +55,26 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// # Examples /// /// ``` - /// use x::y; + /// use x::y; /// - /// let foo = Foo::new(); + /// let foo = Foo::new(); /// - /// // calls bar on foo - /// assert!(foo.bar()); + /// // calls bar on foo + /// assert!(foo.bar()); /// - /// let bar = foo.bar || Foo::bar; + /// let bar = foo.bar || Foo::bar; /// - /// /* multi-line - /// comment */ + /// /* multi-line + /// comment */ /// - /// let multi_line_string = "Foo - /// bar - /// "; + /// let multi_line_string = "Foo + /// bar + /// "; /// /// ``` /// /// ```rust,no_run - /// let foobar = Foo::new().bar(); + /// let foobar = Foo::new().bar(); /// ``` /// /// ```sh diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 68dff45b7..6c43c5d94 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -477,10 +477,10 @@ fn highlight_element( // Simple token-based highlighting COMMENT => { let comment = element.into_token().and_then(ast::Comment::cast)?; - if comment.kind().doc.is_some() { - Highlight::from(HighlightTag::Comment) | HighlightModifier::Documentation - } else { - HighlightTag::Comment.into() + let h = HighlightTag::Comment; + match comment.kind().doc { + Some(_) => h | HighlightModifier::Documentation, + None => h.into(), } } STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs index 40436c5a2..dc12c8f5a 100644 --- a/crates/ra_ide/src/syntax_highlighting/injection.rs +++ b/crates/ra_ide/src/syntax_highlighting/injection.rs @@ -8,8 +8,8 @@ use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; use stdx::SepBy; use crate::{ - call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag, - HighlightedRange, RootDatabase, + call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange, + RootDatabase, }; use super::HighlightedRangeStack; @@ -121,8 +121,7 @@ pub(super) fn extract_doc_comments( range.start(), range.start() + TextSize::try_from(pos).unwrap(), ), - highlight: Highlight::from(HighlightTag::Comment) - | HighlightModifier::Documentation, + highlight: HighlightTag::Comment | HighlightModifier::Documentation, binding_hash: None, }); line_start += range.len() - TextSize::try_from(pos).unwrap(); @@ -168,6 +167,8 @@ pub(super) fn highlight_doc_comment( h.range.start() + start_offset, h.range.end() + end_offset.unwrap_or(start_offset), ); + + h.highlight |= HighlightModifier::Documentation; stack.add(h); } } -- cgit v1.2.3