aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-06-17 14:33:21 +0100
committerPaul Daniel Faria <[email protected]>2020-06-17 14:33:21 +0100
commita951108173349f9ff0b9936ec2af8881fd92fc98 (patch)
treeebb7d11259f69534a167aff03abf579afaa3fe30 /crates/ra_ide/src
parentaae26bc5b864971ef54f4d95d5ed89a6436334e2 (diff)
Ensure all existing doctest code highlights have documentation modifier
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/snapshots/highlight_doctest.html26
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs8
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs9
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
43 <span class="comment documentation">/// # Examples</span> 43 <span class="comment documentation">/// # Examples</span>
44 <span class="comment documentation">///</span> 44 <span class="comment documentation">///</span>
45 <span class="comment documentation">/// ```</span> 45 <span class="comment documentation">/// ```</span>
46 <span class="comment documentation">/// #</span> <span class="attribute">#![</span><span class="function attribute">allow</span><span class="attribute">(unused_mut)]</span> 46 <span class="comment documentation">/// #</span> <span class="attribute documentation">#![</span><span class="function attribute documentation">allow</span><span class="attribute documentation">(unused_mut)]</span>
47 <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>(); 47 <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>();
48 <span class="comment documentation">/// ```</span> 48 <span class="comment documentation">/// ```</span>
49 <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> { 49 <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> {
50 <span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> } 50 <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
55 <span class="comment documentation">/// # Examples</span> 55 <span class="comment documentation">/// # Examples</span>
56 <span class="comment documentation">///</span> 56 <span class="comment documentation">///</span>
57 <span class="comment documentation">/// ```</span> 57 <span class="comment documentation">/// ```</span>
58 <span class="comment documentation">/// </span><span class="keyword">use</span> <span class="module">x</span>::<span class="module">y</span>; 58 <span class="comment documentation">/// </span><span class="keyword documentation">use</span> <span class="module documentation">x</span>::<span class="module documentation">y</span>;
59 <span class="comment documentation">///</span> 59 <span class="comment documentation">///</span>
60 <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>(); 60 <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>();
61 <span class="comment documentation">///</span> 61 <span class="comment documentation">///</span>
62 <span class="comment documentation">/// </span><span class="comment">// calls bar on foo</span> 62 <span class="comment documentation">/// </span><span class="comment documentation">// calls bar on foo</span>
63 <span class="comment documentation">/// </span><span class="macro">assert!</span>(foo.bar()); 63 <span class="comment documentation">/// </span><span class="macro documentation">assert!</span>(foo.bar());
64 <span class="comment documentation">///</span> 64 <span class="comment documentation">///</span>
65 <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>; 65 <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>;
66 <span class="comment documentation">///</span> 66 <span class="comment documentation">///</span>
67 <span class="comment documentation">/// </span><span class="comment">/* multi-line 67 <span class="comment documentation">/// </span><span class="comment documentation">/* multi-line
68 </span><span class="comment documentation">/// </span><span class="comment"> comment */</span> 68 </span><span class="comment documentation">/// </span><span class="comment documentation"> comment */</span>
69 <span class="comment documentation">///</span> 69 <span class="comment documentation">///</span>
70 <span class="comment documentation">/// </span><span class="keyword">let</span> <span class="variable declaration">multi_line_string</span> = <span class="string_literal">"Foo 70 <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
71 </span><span class="comment documentation">/// </span><span class="string_literal"> bar 71 </span><span class="comment documentation">/// </span><span class="string_literal documentation"> bar
72 </span><span class="comment documentation">/// </span><span class="string_literal"> "</span>; 72 </span><span class="comment documentation">/// </span><span class="string_literal documentation"> "</span>;
73 <span class="comment documentation">///</span> 73 <span class="comment documentation">///</span>
74 <span class="comment documentation">/// ```</span> 74 <span class="comment documentation">/// ```</span>
75 <span class="comment documentation">///</span> 75 <span class="comment documentation">///</span>
76 <span class="comment documentation">/// ```rust,no_run</span> 76 <span class="comment documentation">/// ```rust,no_run</span>
77 <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>(); 77 <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>();
78 <span class="comment documentation">/// ```</span> 78 <span class="comment documentation">/// ```</span>
79 <span class="comment documentation">///</span> 79 <span class="comment documentation">///</span>
80 <span class="comment documentation">/// ```sh</span> 80 <span class="comment documentation">/// ```sh</span>
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(
477 // Simple token-based highlighting 477 // Simple token-based highlighting
478 COMMENT => { 478 COMMENT => {
479 let comment = element.into_token().and_then(ast::Comment::cast)?; 479 let comment = element.into_token().and_then(ast::Comment::cast)?;
480 if comment.kind().doc.is_some() { 480 let h = HighlightTag::Comment;
481 Highlight::from(HighlightTag::Comment) | HighlightModifier::Documentation 481 match comment.kind().doc {
482 } else { 482 Some(_) => h | HighlightModifier::Documentation,
483 HighlightTag::Comment.into() 483 None => h.into(),
484 } 484 }
485 } 485 }
486 STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(), 486 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};
8use stdx::SepBy; 8use stdx::SepBy;
9 9
10use crate::{ 10use crate::{
11 call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag, 11 call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange,
12 HighlightedRange, RootDatabase, 12 RootDatabase,
13}; 13};
14 14
15use super::HighlightedRangeStack; 15use super::HighlightedRangeStack;
@@ -121,8 +121,7 @@ pub(super) fn extract_doc_comments(
121 range.start(), 121 range.start(),
122 range.start() + TextSize::try_from(pos).unwrap(), 122 range.start() + TextSize::try_from(pos).unwrap(),
123 ), 123 ),
124 highlight: Highlight::from(HighlightTag::Comment) 124 highlight: HighlightTag::Comment | HighlightModifier::Documentation,
125 | HighlightModifier::Documentation,
126 binding_hash: None, 125 binding_hash: None,
127 }); 126 });
128 line_start += range.len() - TextSize::try_from(pos).unwrap(); 127 line_start += range.len() - TextSize::try_from(pos).unwrap();
@@ -168,6 +167,8 @@ pub(super) fn highlight_doc_comment(
168 h.range.start() + start_offset, 167 h.range.start() + start_offset,
169 h.range.end() + end_offset.unwrap_or(start_offset), 168 h.range.end() + end_offset.unwrap_or(start_offset),
170 ); 169 );
170
171 h.highlight |= HighlightModifier::Documentation;
171 stack.add(h); 172 stack.add(h);
172 } 173 }
173 } 174 }