Ensure all existing doctest code highlights have documentation modifier

This commit is contained in:
Paul Daniel Faria 2020-06-17 09:33:21 -04:00
parent aae26bc5b8
commit a951108173
3 changed files with 22 additions and 21 deletions

View File

@ -43,8 +43,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="comment documentation">/// # Examples</span>
<span class="comment documentation">///</span>
<span class="comment documentation">/// ```</span>
<span class="comment documentation">/// #</span> <span class="attribute">#![</span><span class="function attribute">allow</span><span class="attribute">(unused_mut)]</span>
<span class="comment documentation">/// </span><span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">foo</span>: <span class="struct">Foo</span> = <span class="struct">Foo</span>::<span class="function">new</span>();
<span class="comment documentation">/// #</span> <span class="attribute documentation">#![</span><span class="function attribute documentation">allow</span><span class="attribute documentation">(unused_mut)]</span>
<span class="comment documentation">/// </span><span class="keyword documentation">let</span> <span class="keyword documentation">mut</span> <span class="variable declaration documentation mutable">foo</span>: <span class="struct documentation">Foo</span> = <span class="struct documentation">Foo</span>::<span class="function documentation">new</span>();
<span class="comment documentation">/// ```</span>
<span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration">new</span>() -&gt; <span class="struct">Foo</span> {
<span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> }
@ -55,26 +55,26 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="comment documentation">/// # Examples</span>
<span class="comment documentation">///</span>
<span class="comment documentation">/// ```</span>
<span class="comment documentation">/// </span><span class="keyword">use</span> <span class="module">x</span>::<span class="module">y</span>;
<span class="comment documentation">/// </span><span class="keyword documentation">use</span> <span class="module documentation">x</span>::<span class="module documentation">y</span>;
<span class="comment documentation">///</span>
<span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">foo</span> = <span class="struct">Foo</span>::<span class="function">new</span>();
<span class="comment documentation">/// </span><span class="keyword documentation">let</span> <span class="variable declaration documentation">foo</span> = <span class="struct documentation">Foo</span>::<span class="function documentation">new</span>();
<span class="comment documentation">///</span>
<span class="comment documentation">/// </span><span class="comment">// calls bar on foo</span>
<span class="comment documentation">/// </span><span class="macro">assert!</span>(foo.bar());
<span class="comment documentation">/// </span><span class="comment documentation">// calls bar on foo</span>
<span class="comment documentation">/// </span><span class="macro documentation">assert!</span>(foo.bar());
<span class="comment documentation">///</span>
<span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">bar</span> = <span class="variable">foo</span>.<span class="field">bar</span> || <span class="struct">Foo</span>::<span class="constant">bar</span>;
<span class="comment documentation">/// </span><span class="keyword documentation">let</span> <span class="variable declaration documentation">bar</span> = <span class="variable documentation">foo</span>.<span class="field documentation">bar</span> || <span class="struct documentation">Foo</span>::<span class="constant documentation">bar</span>;
<span class="comment documentation">///</span>
<span class="comment documentation">/// </span><span class="comment">/* multi-line
</span><span class="comment documentation">/// </span><span class="comment"> comment */</span>
<span class="comment documentation">/// </span><span class="comment documentation">/* multi-line
</span><span class="comment documentation">/// </span><span class="comment documentation"> comment */</span>
<span class="comment documentation">///</span>
<span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">multi_line_string</span> = <span class="string_literal">"Foo
</span><span class="comment documentation">/// </span><span class="string_literal"> bar
</span><span class="comment documentation">/// </span><span class="string_literal"> "</span>;
<span class="comment documentation">/// </span><span class="keyword documentation">let</span> <span class="variable declaration documentation">multi_line_string</span> = <span class="string_literal documentation">"Foo
</span><span class="comment documentation">/// </span><span class="string_literal documentation"> bar
</span><span class="comment documentation">/// </span><span class="string_literal documentation"> "</span>;
<span class="comment documentation">///</span>
<span class="comment documentation">/// ```</span>
<span class="comment documentation">///</span>
<span class="comment documentation">/// ```rust,no_run</span>
<span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">foobar</span> = <span class="struct">Foo</span>::<span class="function">new</span>().<span class="function">bar</span>();
<span class="comment documentation">/// </span><span class="keyword documentation">let</span> <span class="variable declaration documentation">foobar</span> = <span class="struct documentation">Foo</span>::<span class="function documentation">new</span>().<span class="function documentation">bar</span>();
<span class="comment documentation">/// ```</span>
<span class="comment documentation">///</span>
<span class="comment documentation">/// ```sh</span>

View File

@ -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(),

View File

@ -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);
}
}