aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/lib.rs6
-rw-r--r--crates/ra_ide/src/prime_caches.rs2
-rw-r--r--crates/ra_ide/src/snapshots/highlight_doctest.html23
-rw-r--r--crates/ra_ide/src/snapshots/highlight_injection.html1
-rw-r--r--crates/ra_ide/src/snapshots/highlight_strings.html1
-rw-r--r--crates/ra_ide/src/snapshots/highlight_unsafe.html1
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html9
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html1
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs100
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs3
-rw-r--r--crates/ra_ide/src/syntax_highlighting/injection.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs22
12 files changed, 139 insertions, 32 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 28f686767..375da1f45 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -440,12 +440,14 @@ impl Analysis {
440 440
441 /// Computes syntax highlighting for the given file 441 /// Computes syntax highlighting for the given file
442 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { 442 pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
443 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None)) 443 self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false))
444 } 444 }
445 445
446 /// Computes syntax highlighting for the given file range. 446 /// Computes syntax highlighting for the given file range.
447 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> { 447 pub fn highlight_range(&self, frange: FileRange) -> Cancelable<Vec<HighlightedRange>> {
448 self.with_db(|db| syntax_highlighting::highlight(db, frange.file_id, Some(frange.range))) 448 self.with_db(|db| {
449 syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false)
450 })
449 } 451 }
450 452
451 /// Computes syntax highlighting for the given file. 453 /// Computes syntax highlighting for the given file.
diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs
index 90bf7d25f..c5ab5a1d8 100644
--- a/crates/ra_ide/src/prime_caches.rs
+++ b/crates/ra_ide/src/prime_caches.rs
@@ -7,6 +7,6 @@ use crate::{FileId, RootDatabase};
7 7
8pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) { 8pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) {
9 for file in files { 9 for file in files {
10 let _ = crate::syntax_highlighting::highlight(db, file, None); 10 let _ = crate::syntax_highlighting::highlight(db, file, None, false);
11 } 11 }
12} 12}
diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html
index 0ae8c7efc..5228df267 100644
--- a/crates/ra_ide/src/snapshots/highlight_doctest.html
+++ b/crates/ra_ide/src/snapshots/highlight_doctest.html
@@ -25,22 +25,29 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
31.control { font-style: italic; } 32.control { font-style: italic; }
32</style> 33</style>
33<pre><code><span class="keyword">impl</span> <span class="unresolved_reference">Foo</span> { 34<pre><code><span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
35 <span class="field declaration">bar</span>: <span class="builtin_type">bool</span>,
36}
37
38<span class="keyword">impl</span> <span class="struct">Foo</span> {
39 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="constant declaration">bar</span>: <span class="builtin_type">bool</span> = <span class="bool_literal">true</span>;
40
34 <span class="comment">/// Constructs a new `Foo`.</span> 41 <span class="comment">/// Constructs a new `Foo`.</span>
35 <span class="comment">///</span> 42 <span class="comment">///</span>
36 <span class="comment">/// # Examples</span> 43 <span class="comment">/// # Examples</span>
37 <span class="comment">///</span> 44 <span class="comment">///</span>
38 <span class="comment">/// ```</span> 45 <span class="comment">/// ```</span>
39 <span class="comment">/// #</span> <span class="attribute">#![</span><span class="function attribute">allow</span><span class="attribute">(unused_mut)]</span> 46 <span class="comment">/// #</span> <span class="attribute">#![</span><span class="function attribute">allow</span><span class="attribute">(unused_mut)]</span>
40 <span class="comment">/// </span><span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">foo</span>: <span class="unresolved_reference">Foo</span> = <span class="unresolved_reference">Foo</span>::<span class="unresolved_reference">new</span>(); 47 <span class="comment">/// </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>();
41 <span class="comment">/// ```</span> 48 <span class="comment">/// ```</span>
42 <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration">new</span>() -&gt; <span class="unresolved_reference">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> {
43 <span class="unresolved_reference">Foo</span> { } 50 <span class="struct">Foo</span> { <span class="field">bar</span>: <span class="bool_literal">true</span> }
44 } 51 }
45 52
46 <span class="comment">/// `bar` method on `Foo`.</span> 53 <span class="comment">/// `bar` method on `Foo`.</span>
@@ -48,11 +55,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
48 <span class="comment">/// # Examples</span> 55 <span class="comment">/// # Examples</span>
49 <span class="comment">///</span> 56 <span class="comment">///</span>
50 <span class="comment">/// ```</span> 57 <span class="comment">/// ```</span>
51 <span class="comment">/// </span><span class="keyword">let</span> <span class="variable declaration">foo</span> = <span class="unresolved_reference">Foo</span>::<span class="unresolved_reference">new</span>(); 58 <span class="comment">/// </span><span class="keyword">use</span> <span class="module">x</span>::<span class="module">y</span>;
59 <span class="comment">///</span>
60 <span class="comment">/// </span><span class="keyword">let</span> <span class="variable declaration">foo</span> = <span class="struct">Foo</span>::<span class="function">new</span>();
52 <span class="comment">///</span> 61 <span class="comment">///</span>
53 <span class="comment">/// </span><span class="comment">// calls bar on foo</span> 62 <span class="comment">/// </span><span class="comment">// calls bar on foo</span>
54 <span class="comment">/// </span><span class="macro">assert!</span>(foo.bar()); 63 <span class="comment">/// </span><span class="macro">assert!</span>(foo.bar());
55 <span class="comment">///</span> 64 <span class="comment">///</span>
65 <span class="comment">/// </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>;
66 <span class="comment">///</span>
56 <span class="comment">/// </span><span class="comment">/* multi-line 67 <span class="comment">/// </span><span class="comment">/* multi-line
57 </span><span class="comment">/// </span><span class="comment"> comment */</span> 68 </span><span class="comment">/// </span><span class="comment"> comment */</span>
58 <span class="comment">///</span> 69 <span class="comment">///</span>
@@ -63,7 +74,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
63 <span class="comment">/// ```</span> 74 <span class="comment">/// ```</span>
64 <span class="comment">///</span> 75 <span class="comment">///</span>
65 <span class="comment">/// ```</span> 76 <span class="comment">/// ```</span>
66 <span class="comment">/// </span><span class="keyword">let</span> <span class="variable declaration">foobar</span> = <span class="unresolved_reference">Foo</span>::<span class="unresolved_reference">new</span>().<span class="unresolved_reference">bar</span>(); 77 <span class="comment">/// </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>();
67 <span class="comment">/// ```</span> 78 <span class="comment">/// ```</span>
68 <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">foo</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">bool</span> { 79 <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">foo</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">bool</span> {
69 <span class="bool_literal">true</span> 80 <span class="bool_literal">true</span>
diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html
index dec06eb51..e1c9d3523 100644
--- a/crates/ra_ide/src/snapshots/highlight_injection.html
+++ b/crates/ra_ide/src/snapshots/highlight_injection.html
@@ -25,6 +25,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html
index 849eb3b73..666b48fd0 100644
--- a/crates/ra_ide/src/snapshots/highlight_strings.html
+++ b/crates/ra_ide/src/snapshots/highlight_strings.html
@@ -25,6 +25,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
diff --git a/crates/ra_ide/src/snapshots/highlight_unsafe.html b/crates/ra_ide/src/snapshots/highlight_unsafe.html
index bd24e6e38..e1540499b 100644
--- a/crates/ra_ide/src/snapshots/highlight_unsafe.html
+++ b/crates/ra_ide/src/snapshots/highlight_unsafe.html
@@ -25,6 +25,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 33548d43c..52912dc93 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -25,6 +25,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
@@ -62,6 +63,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
62 } 63 }
63} 64}
64 65
66<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
67 ($expr:expr) =&gt; {
68 $expr
69 }
70}
71
65<span class="comment">// comment</span> 72<span class="comment">// comment</span>
66<span class="keyword">fn</span> <span class="function declaration">main</span>() { 73<span class="keyword">fn</span> <span class="function declaration">main</span>() {
67 <span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>); 74 <span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
@@ -80,6 +87,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
80 <span class="comment">// Do nothing</span> 87 <span class="comment">// Do nothing</span>
81 } 88 }
82 89
90 <span class="macro">noop!</span>(<span class="macro">noop</span><span class="macro">!</span>(<span class="numeric_literal">1</span>));
91
83 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>; 92 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
84 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; 93 <span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
85 <span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>; 94 <span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
index 1ab06182c..1d7f04882 100644
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
@@ -25,6 +25,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
25.variable { color: #DCDCCC; } 25.variable { color: #DCDCCC; }
26.format_specifier { color: #CC696B; } 26.format_specifier { color: #CC696B; }
27.mutable { text-decoration: underline; } 27.mutable { text-decoration: underline; }
28.unresolved_reference { color: #FC5555; }
28 29
29.keyword { color: #F0DFAF; font-weight: bold; } 30.keyword { color: #F0DFAF; font-weight: bold; }
30.keyword.unsafe { color: #BC8383; font-weight: bold; } 31.keyword.unsafe { color: #BC8383; font-weight: bold; }
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index ab45c364a..5a4de450c 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -44,6 +44,7 @@ pub(crate) fn highlight(
44 db: &RootDatabase, 44 db: &RootDatabase,
45 file_id: FileId, 45 file_id: FileId,
46 range_to_highlight: Option<TextRange>, 46 range_to_highlight: Option<TextRange>,
47 syntactic_name_ref_highlighting: bool,
47) -> Vec<HighlightedRange> { 48) -> Vec<HighlightedRange> {
48 let _p = profile("highlight"); 49 let _p = profile("highlight");
49 let sema = Semantics::new(db); 50 let sema = Semantics::new(db);
@@ -104,6 +105,7 @@ pub(crate) fn highlight(
104 if let Some((highlight, binding_hash)) = highlight_element( 105 if let Some((highlight, binding_hash)) = highlight_element(
105 &sema, 106 &sema,
106 &mut bindings_shadow_count, 107 &mut bindings_shadow_count,
108 syntactic_name_ref_highlighting,
107 name.syntax().clone().into(), 109 name.syntax().clone().into(),
108 ) { 110 ) {
109 stack.add(HighlightedRange { 111 stack.add(HighlightedRange {
@@ -160,23 +162,25 @@ pub(crate) fn highlight(
160 // Check if macro takes a format string and remember it for highlighting later. 162 // Check if macro takes a format string and remember it for highlighting later.
161 // The macros that accept a format string expand to a compiler builtin macros 163 // The macros that accept a format string expand to a compiler builtin macros
162 // `format_args` and `format_args_nl`. 164 // `format_args` and `format_args_nl`.
163 if let Some(fmt_macro_call) = parent.parent().and_then(ast::MacroCall::cast) { 165 if let Some(name) = parent
164 if let Some(name) = 166 .parent()
165 fmt_macro_call.path().and_then(|p| p.segment()).and_then(|s| s.name_ref()) 167 .and_then(ast::MacroCall::cast)
166 { 168 .and_then(|mc| mc.path())
167 match name.text().as_str() { 169 .and_then(|p| p.segment())
168 "format_args" | "format_args_nl" => { 170 .and_then(|s| s.name_ref())
169 format_string = parent 171 {
170 .children_with_tokens() 172 match name.text().as_str() {
171 .filter(|t| t.kind() != WHITESPACE) 173 "format_args" | "format_args_nl" => {
172 .nth(1) 174 format_string = parent
173 .filter(|e| { 175 .children_with_tokens()
174 ast::String::can_cast(e.kind()) 176 .filter(|t| t.kind() != WHITESPACE)
175 || ast::RawString::can_cast(e.kind()) 177 .nth(1)
176 }) 178 .filter(|e| {
177 } 179 ast::String::can_cast(e.kind())
178 _ => {} 180 || ast::RawString::can_cast(e.kind())
181 })
179 } 182 }
183 _ => {}
180 } 184 }
181 } 185 }
182 186
@@ -198,9 +202,12 @@ pub(crate) fn highlight(
198 202
199 let is_format_string = format_string.as_ref() == Some(&element_to_highlight); 203 let is_format_string = format_string.as_ref() == Some(&element_to_highlight);
200 204
201 if let Some((highlight, binding_hash)) = 205 if let Some((highlight, binding_hash)) = highlight_element(
202 highlight_element(&sema, &mut bindings_shadow_count, element_to_highlight.clone()) 206 &sema,
203 { 207 &mut bindings_shadow_count,
208 syntactic_name_ref_highlighting,
209 element_to_highlight.clone(),
210 ) {
204 stack.add(HighlightedRange { range, highlight, binding_hash }); 211 stack.add(HighlightedRange { range, highlight, binding_hash });
205 if let Some(string) = 212 if let Some(string) =
206 element_to_highlight.as_token().cloned().and_then(ast::String::cast) 213 element_to_highlight.as_token().cloned().and_then(ast::String::cast)
@@ -408,6 +415,7 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
408fn highlight_element( 415fn highlight_element(
409 sema: &Semantics<RootDatabase>, 416 sema: &Semantics<RootDatabase>,
410 bindings_shadow_count: &mut FxHashMap<Name, u32>, 417 bindings_shadow_count: &mut FxHashMap<Name, u32>,
418 syntactic_name_ref_highlighting: bool,
411 element: SyntaxElement, 419 element: SyntaxElement,
412) -> Option<(Highlight, Option<u64>)> { 420) -> Option<(Highlight, Option<u64>)> {
413 let db = sema.db; 421 let db = sema.db;
@@ -461,6 +469,7 @@ fn highlight_element(
461 } 469 }
462 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 470 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
463 }, 471 },
472 None if syntactic_name_ref_highlighting => highlight_name_ref_by_syntax(name_ref),
464 None => HighlightTag::UnresolvedReference.into(), 473 None => HighlightTag::UnresolvedReference.into(),
465 } 474 }
466 } 475 }
@@ -493,6 +502,9 @@ fn highlight_element(
493 h |= HighlightModifier::Unsafe; 502 h |= HighlightModifier::Unsafe;
494 h 503 h
495 } 504 }
505 T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
506 Highlight::new(HighlightTag::Macro)
507 }
496 508
497 k if k.is_keyword() => { 509 k if k.is_keyword() => {
498 let h = Highlight::new(HighlightTag::Keyword); 510 let h = Highlight::new(HighlightTag::Keyword);
@@ -609,3 +621,53 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
609 621
610 tag.into() 622 tag.into()
611} 623}
624
625fn highlight_name_ref_by_syntax(name: ast::NameRef) -> Highlight {
626 let default = HighlightTag::UnresolvedReference;
627
628 let parent = match name.syntax().parent() {
629 Some(it) => it,
630 _ => return default.into(),
631 };
632
633 let tag = match parent.kind() {
634 METHOD_CALL_EXPR => HighlightTag::Function,
635 FIELD_EXPR => HighlightTag::Field,
636 PATH_SEGMENT => {
637 let path = match parent.parent().and_then(ast::Path::cast) {
638 Some(it) => it,
639 _ => return default.into(),
640 };
641 let expr = match path.syntax().parent().and_then(ast::PathExpr::cast) {
642 Some(it) => it,
643 _ => {
644 // within path, decide whether it is module or adt by checking for uppercase name
645 return if name.text().chars().next().unwrap_or_default().is_uppercase() {
646 HighlightTag::Struct
647 } else {
648 HighlightTag::Module
649 }
650 .into();
651 }
652 };
653 let parent = match expr.syntax().parent() {
654 Some(it) => it,
655 None => return default.into(),
656 };
657
658 match parent.kind() {
659 CALL_EXPR => HighlightTag::Function,
660 _ => {
661 if name.text().chars().next().unwrap_or_default().is_uppercase() {
662 HighlightTag::Struct
663 } else {
664 HighlightTag::Constant
665 }
666 }
667 }
668 }
669 _ => default,
670 };
671
672 tag.into()
673}
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 5bada6252..853b4a20f 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -19,7 +19,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
19 ) 19 )
20 } 20 }
21 21
22 let ranges = highlight(db, file_id, None); 22 let ranges = highlight(db, file_id, None, false);
23 let text = parse.tree().syntax().to_string(); 23 let text = parse.tree().syntax().to_string();
24 let mut prev_pos = TextSize::from(0); 24 let mut prev_pos = TextSize::from(0);
25 let mut buf = String::new(); 25 let mut buf = String::new();
@@ -84,6 +84,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
84.variable { color: #DCDCCC; } 84.variable { color: #DCDCCC; }
85.format_specifier { color: #CC696B; } 85.format_specifier { color: #CC696B; }
86.mutable { text-decoration: underline; } 86.mutable { text-decoration: underline; }
87.unresolved_reference { color: #FC5555; }
87 88
88.keyword { color: #F0DFAF; font-weight: bold; } 89.keyword { color: #F0DFAF; font-weight: bold; }
89.keyword.unsafe { color: #BC8383; font-weight: bold; } 90.keyword.unsafe { color: #BC8383; font-weight: bold; }
diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs
index 3575a0fc6..a02ffe59e 100644
--- a/crates/ra_ide/src/syntax_highlighting/injection.rs
+++ b/crates/ra_ide/src/syntax_highlighting/injection.rs
@@ -137,7 +137,7 @@ pub(super) fn highlight_doc_comment(
137 let (analysis, tmp_file_id) = Analysis::from_single_file(text); 137 let (analysis, tmp_file_id) = Analysis::from_single_file(text);
138 138
139 stack.push(); 139 stack.push();
140 for mut h in analysis.highlight(tmp_file_id).unwrap() { 140 for mut h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() {
141 // Determine start offset and end offset in case of multi-line ranges 141 // Determine start offset and end offset in case of multi-line ranges
142 let mut start_offset = None; 142 let mut start_offset = None;
143 let mut end_offset = None; 143 let mut end_offset = None;
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 949bf59a0..062b3ff4a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -43,6 +43,12 @@ def_fn! {
43 } 43 }
44} 44}
45 45
46macro_rules! noop {
47 ($expr:expr) => {
48 $expr
49 }
50}
51
46// comment 52// comment
47fn main() { 53fn main() {
48 println!("Hello, {}!", 92); 54 println!("Hello, {}!", 92);
@@ -61,6 +67,8 @@ fn main() {
61 // Do nothing 67 // Do nothing
62 } 68 }
63 69
70 noop!(noop!(1));
71
64 let mut x = 42; 72 let mut x = 42;
65 let y = &mut x; 73 let y = &mut x;
66 let z = &y; 74 let z = &y;
@@ -279,7 +287,13 @@ fn main() {
279fn test_highlight_doctest() { 287fn test_highlight_doctest() {
280 check_highlighting( 288 check_highlighting(
281 r#" 289 r#"
290struct Foo {
291 bar: bool,
292}
293
282impl Foo { 294impl Foo {
295 pub const bar: bool = true;
296
283 /// Constructs a new `Foo`. 297 /// Constructs a new `Foo`.
284 /// 298 ///
285 /// # Examples 299 /// # Examples
@@ -289,7 +303,7 @@ impl Foo {
289 /// let mut foo: Foo = Foo::new(); 303 /// let mut foo: Foo = Foo::new();
290 /// ``` 304 /// ```
291 pub const fn new() -> Foo { 305 pub const fn new() -> Foo {
292 Foo { } 306 Foo { bar: true }
293 } 307 }
294 308
295 /// `bar` method on `Foo`. 309 /// `bar` method on `Foo`.
@@ -297,11 +311,15 @@ impl Foo {
297 /// # Examples 311 /// # Examples
298 /// 312 ///
299 /// ``` 313 /// ```
314 /// use x::y;
315 ///
300 /// let foo = Foo::new(); 316 /// let foo = Foo::new();
301 /// 317 ///
302 /// // calls bar on foo 318 /// // calls bar on foo
303 /// assert!(foo.bar()); 319 /// assert!(foo.bar());
304 /// 320 ///
321 /// let bar = foo.bar || Foo::bar;
322 ///
305 /// /* multi-line 323 /// /* multi-line
306 /// comment */ 324 /// comment */
307 /// 325 ///
@@ -322,7 +340,7 @@ impl Foo {
322 .trim(), 340 .trim(),
323 "crates/ra_ide/src/snapshots/highlight_doctest.html", 341 "crates/ra_ide/src/snapshots/highlight_doctest.html",
324 false, 342 false,
325 ) 343 );
326} 344}
327 345
328/// Highlights the code given by the `ra_fixture` argument, renders the 346/// Highlights the code given by the `ra_fixture` argument, renders the