diff options
author | George Fraser <[email protected]> | 2020-05-10 19:26:19 +0100 |
---|---|---|
committer | George Fraser <[email protected]> | 2020-05-10 21:11:14 +0100 |
commit | 63b75a40c8c9e1f24fbd21c423f62f303281b77c (patch) | |
tree | bef6f11c4190be0f0bfd27365630d701ea51bc55 /crates/ra_ide/src | |
parent | 3f1c73633eb3e5d8a2df3a72dc772087cfb18be4 (diff) |
Color `for` as a regular keyword when it's part of impl _ for _
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/snapshots/highlighting.html | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 10 |
3 files changed, 28 insertions, 1 deletions
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index c67df5c39..635fe5cf9 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html | |||
@@ -33,6 +33,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
33 | <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>, | 33 | <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>, |
34 | } | 34 | } |
35 | 35 | ||
36 | <span class="keyword">trait</span> <span class="trait declaration">Bar</span> { | ||
37 | <span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -> <span class="builtin_type">i32</span>; | ||
38 | } | ||
39 | |||
40 | <span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> { | ||
41 | <span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -> <span class="builtin_type">i32</span> { | ||
42 | <span class="keyword">self</span>.<span class="field">x</span> | ||
43 | } | ||
44 | } | ||
45 | |||
36 | <span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>; | 46 | <span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>; |
37 | 47 | ||
38 | <span class="keyword">fn</span> <span class="function declaration">foo</span><<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>>() -> <span class="type_param">T</span> { | 48 | <span class="keyword">fn</span> <span class="function declaration">foo</span><<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>>() -> <span class="type_param">T</span> { |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 16123c5cb..be57eeb0a 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -403,13 +403,13 @@ fn highlight_element( | |||
403 | T![break] | 403 | T![break] |
404 | | T![continue] | 404 | | T![continue] |
405 | | T![else] | 405 | | T![else] |
406 | | T![for] | ||
407 | | T![if] | 406 | | T![if] |
408 | | T![loop] | 407 | | T![loop] |
409 | | T![match] | 408 | | T![match] |
410 | | T![return] | 409 | | T![return] |
411 | | T![while] | 410 | | T![while] |
412 | | T![in] => h | HighlightModifier::ControlFlow, | 411 | | T![in] => h | HighlightModifier::ControlFlow, |
412 | T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow, | ||
413 | T![unsafe] => h | HighlightModifier::Unsafe, | 413 | T![unsafe] => h | HighlightModifier::Unsafe, |
414 | _ => h, | 414 | _ => h, |
415 | } | 415 | } |
@@ -433,6 +433,13 @@ fn highlight_element( | |||
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | fn is_child_of_impl(element: SyntaxElement) -> bool { | ||
437 | match element.parent() { | ||
438 | Some(e) => e.kind() == IMPL_DEF, | ||
439 | _ => false, | ||
440 | } | ||
441 | } | ||
442 | |||
436 | fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { | 443 | fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { |
437 | match def { | 444 | match def { |
438 | Definition::Macro(_) => HighlightTag::Macro, | 445 | Definition::Macro(_) => HighlightTag::Macro, |
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 7975755b2..eb43a23da 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -17,6 +17,16 @@ struct Foo { | |||
17 | pub y: i32, | 17 | pub y: i32, |
18 | } | 18 | } |
19 | 19 | ||
20 | trait Bar { | ||
21 | fn bar(&self) -> i32; | ||
22 | } | ||
23 | |||
24 | impl Bar for Foo { | ||
25 | fn bar(&self) -> i32 { | ||
26 | self.x | ||
27 | } | ||
28 | } | ||
29 | |||
20 | static mut STATIC_MUT: i32 = 0; | 30 | static mut STATIC_MUT: i32 = 0; |
21 | 31 | ||
22 | fn foo<'a, T>() -> T { | 32 | fn foo<'a, T>() -> T { |