aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-16 12:40:51 +0100
committerGitHub <[email protected]>2020-06-16 12:40:51 +0100
commit4342b717158eeb9aff20d1958229ffcbca17f1c7 (patch)
treeddcbbfe6fcaaac83449fe612c971044e19680365 /crates/ra_ide/src
parent83a16e825da2767aaee1d62447eb94f4d7de8881 (diff)
parentc4b3db0c2f307d1d782af88ded260e4c6593cae0 (diff)
Merge #4876
4876: Syntactic highlighting of NAME_REF for injections r=matklad a=ltentrup This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage. It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references. It also adds a color to unresolved references in HTML encoding. Follow up of #4683. Fixes #4809. Co-authored-by: Leander Tentrup <[email protected]>
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.html1
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html1
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs63
-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.rs14
12 files changed, 102 insertions, 16 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 5c2ff6ab5..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; }
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 bbcd52a1c..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 {
@@ -200,9 +202,12 @@ pub(crate) fn highlight(
200 202
201 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);
202 204
203 if let Some((highlight, binding_hash)) = 205 if let Some((highlight, binding_hash)) = highlight_element(
204 highlight_element(&sema, &mut bindings_shadow_count, element_to_highlight.clone()) 206 &sema,
205 { 207 &mut bindings_shadow_count,
208 syntactic_name_ref_highlighting,
209 element_to_highlight.clone(),
210 ) {
206 stack.add(HighlightedRange { range, highlight, binding_hash }); 211 stack.add(HighlightedRange { range, highlight, binding_hash });
207 if let Some(string) = 212 if let Some(string) =
208 element_to_highlight.as_token().cloned().and_then(ast::String::cast) 213 element_to_highlight.as_token().cloned().and_then(ast::String::cast)
@@ -410,6 +415,7 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
410fn highlight_element( 415fn highlight_element(
411 sema: &Semantics<RootDatabase>, 416 sema: &Semantics<RootDatabase>,
412 bindings_shadow_count: &mut FxHashMap<Name, u32>, 417 bindings_shadow_count: &mut FxHashMap<Name, u32>,
418 syntactic_name_ref_highlighting: bool,
413 element: SyntaxElement, 419 element: SyntaxElement,
414) -> Option<(Highlight, Option<u64>)> { 420) -> Option<(Highlight, Option<u64>)> {
415 let db = sema.db; 421 let db = sema.db;
@@ -463,6 +469,7 @@ fn highlight_element(
463 } 469 }
464 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), 470 NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
465 }, 471 },
472 None if syntactic_name_ref_highlighting => highlight_name_ref_by_syntax(name_ref),
466 None => HighlightTag::UnresolvedReference.into(), 473 None => HighlightTag::UnresolvedReference.into(),
467 } 474 }
468 } 475 }
@@ -614,3 +621,53 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
614 621
615 tag.into() 622 tag.into()
616} 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 070b24f45..062b3ff4a 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -287,7 +287,13 @@ fn main() {
287fn test_highlight_doctest() { 287fn test_highlight_doctest() {
288 check_highlighting( 288 check_highlighting(
289 r#" 289 r#"
290struct Foo {
291 bar: bool,
292}
293
290impl Foo { 294impl Foo {
295 pub const bar: bool = true;
296
291 /// Constructs a new `Foo`. 297 /// Constructs a new `Foo`.
292 /// 298 ///
293 /// # Examples 299 /// # Examples
@@ -297,7 +303,7 @@ impl Foo {
297 /// let mut foo: Foo = Foo::new(); 303 /// let mut foo: Foo = Foo::new();
298 /// ``` 304 /// ```
299 pub const fn new() -> Foo { 305 pub const fn new() -> Foo {
300 Foo { } 306 Foo { bar: true }
301 } 307 }
302 308
303 /// `bar` method on `Foo`. 309 /// `bar` method on `Foo`.
@@ -305,11 +311,15 @@ impl Foo {
305 /// # Examples 311 /// # Examples
306 /// 312 ///
307 /// ``` 313 /// ```
314 /// use x::y;
315 ///
308 /// let foo = Foo::new(); 316 /// let foo = Foo::new();
309 /// 317 ///
310 /// // calls bar on foo 318 /// // calls bar on foo
311 /// assert!(foo.bar()); 319 /// assert!(foo.bar());
312 /// 320 ///
321 /// let bar = foo.bar || Foo::bar;
322 ///
313 /// /* multi-line 323 /// /* multi-line
314 /// comment */ 324 /// comment */
315 /// 325 ///
@@ -330,7 +340,7 @@ impl Foo {
330 .trim(), 340 .trim(),
331 "crates/ra_ide/src/snapshots/highlight_doctest.html", 341 "crates/ra_ide/src/snapshots/highlight_doctest.html",
332 false, 342 false,
333 ) 343 );
334} 344}
335 345
336/// Highlights the code given by the `ra_fixture` argument, renders the 346/// Highlights the code given by the `ra_fixture` argument, renders the