diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html index f92a0aba5e..f61c0daa50 100644 --- a/crates/ra_ide/src/snapshots/highlight_doctest.html +++ b/crates/ra_ide/src/snapshots/highlight_doctest.html @@ -39,48 +39,48 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd impl Foo { pub const bar: bool = true; - /// Constructs a new `Foo`. - /// - /// # Examples - /// - /// ``` - /// # #![allow(unused_mut)] - /// let mut foo: Foo = Foo::new(); - /// ``` + /// Constructs a new `Foo`. + /// + /// # Examples + /// + /// ``` + /// # #![allow(unused_mut)] + /// let mut foo: Foo = Foo::new(); + /// ``` pub const fn new() -> Foo { Foo { bar: true } } - /// `bar` method on `Foo`. - /// - /// # Examples - /// - /// ``` - /// use x::y; - /// - /// let foo = Foo::new(); - /// - /// // calls bar on foo - /// assert!(foo.bar()); - /// - /// let bar = foo.bar || Foo::bar; - /// - /// /* multi-line - /// comment */ - /// - /// let multi_line_string = "Foo - /// bar - /// "; - /// - /// ``` - /// - /// ```rust,no_run - /// let foobar = Foo::new().bar(); - /// ``` - /// - /// ```sh - /// echo 1 - /// ``` + /// `bar` method on `Foo`. + /// + /// # Examples + /// + /// ``` + /// use x::y; + /// + /// let foo = Foo::new(); + /// + /// // calls bar on foo + /// assert!(foo.bar()); + /// + /// let bar = foo.bar || Foo::bar; + /// + /// /* multi-line + /// comment */ + /// + /// let multi_line_string = "Foo + /// bar + /// "; + /// + /// ``` + /// + /// ```rust,no_run + /// let foobar = Foo::new().bar(); + /// ``` + /// + /// ```sh + /// echo 1 + /// ``` pub fn foo(&self) -> bool { true } diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 854b6cc6d6..f8f790e590 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -489,7 +489,14 @@ fn highlight_element( } // Simple token-based highlighting - COMMENT => HighlightTag::Comment.into(), + COMMENT => { + let comment = element.into_token().and_then(ast::Comment::cast)?; + 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(), ATTR => HighlightTag::Attribute.into(), INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs index 929a5cc5c0..415f24a6d3 100644 --- a/crates/ra_ide/src/syntax_highlighting/injection.rs +++ b/crates/ra_ide/src/syntax_highlighting/injection.rs @@ -7,7 +7,10 @@ use hir::Semantics; use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; use stdx::SepBy; -use crate::{call_info::ActiveParameter, Analysis, HighlightTag, HighlightedRange, RootDatabase}; +use crate::{ + call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange, + RootDatabase, +}; use super::HighlightedRangeStack; @@ -118,7 +121,7 @@ pub(super) fn extract_doc_comments( range.start(), range.start() + TextSize::try_from(pos).unwrap(), ), - highlight: HighlightTag::Comment.into(), + highlight: HighlightTag::Comment | HighlightModifier::Documentation, binding_hash: None, }); line_start += range.len() - TextSize::try_from(pos).unwrap(); @@ -164,6 +167,7 @@ pub(super) fn highlight_doc_comment( h.range.start() + start_offset, h.range.end() + end_offset.unwrap_or(start_offset), ); + stack.add(h); } } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 400d22fb64..93bbb4b4dc 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -56,6 +56,7 @@ pub enum HighlightModifier { /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is /// not. Definition, + Documentation, Mutable, Unsafe, } @@ -108,6 +109,7 @@ impl HighlightModifier { HighlightModifier::Attribute, HighlightModifier::ControlFlow, HighlightModifier::Definition, + HighlightModifier::Documentation, HighlightModifier::Mutable, HighlightModifier::Unsafe, ]; @@ -117,6 +119,7 @@ impl HighlightModifier { HighlightModifier::Attribute => "attribute", HighlightModifier::ControlFlow => "control", HighlightModifier::Definition => "declaration", + HighlightModifier::Documentation => "documentation", HighlightModifier::Mutable => "mutable", HighlightModifier::Unsafe => "unsafe", } diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 055c974557..ec153097ef 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -331,6 +331,7 @@ fn semantic_token_type_and_modifiers( let modifier = match modifier { HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER, HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION, + HighlightModifier::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION, HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW, HighlightModifier::Mutable => semantic_tokens::MUTABLE, HighlightModifier::Unsafe => semantic_tokens::UNSAFE,