From c476f71bdf83e930ebe5c2ad2754f24ee0925c32 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jun 2020 15:03:14 +0200 Subject: [PATCH 1/2] Highlight only the unsafe operator itself --- crates/ra_ide/src/syntax_highlighting.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 9ff7356c94..ab45c364a8 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -480,12 +480,8 @@ fn highlight_element( _ => h, } } - PREFIX_EXPR => { - let prefix_expr = element.into_node().and_then(ast::PrefixExpr::cast)?; - match prefix_expr.op_kind() { - Some(ast::PrefixOp::Deref) => {} - _ => return None, - } + T![*] => { + let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; let expr = prefix_expr.expr()?; let ty = sema.type_of_expr(&expr)?; From 3b4d000250ae142288408cfe2abe7c10d4495c92 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 8 Jun 2020 15:23:03 +0200 Subject: [PATCH 2/2] Better unsafe highlihgting tests --- crates/ra_ide/src/snapshots/highlight_doctest.html | 3 ++- crates/ra_ide/src/snapshots/highlight_injection.html | 3 ++- crates/ra_ide/src/snapshots/highlight_strings.html | 3 ++- crates/ra_ide/src/snapshots/highlight_unsafe.html | 5 +++-- crates/ra_ide/src/snapshots/highlighting.html | 3 ++- crates/ra_ide/src/snapshots/rainbow_highlighting.html | 3 ++- crates/ra_ide/src/syntax_highlighting/html.rs | 3 ++- crates/ra_ide/src/syntax_highlighting/tests.rs | 2 +- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html index 2f2d8c900e..0ae8c7efcd 100644 --- a/crates/ra_ide/src/snapshots/highlight_doctest.html +++ b/crates/ra_ide/src/snapshots/highlight_doctest.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html index fcdc98201f..dec06eb518 100644 --- a/crates/ra_ide/src/snapshots/highlight_injection.html +++ b/crates/ra_ide/src/snapshots/highlight_injection.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html index 6a5cf0e744..849eb3b734 100644 --- a/crates/ra_ide/src/snapshots/highlight_strings.html +++ b/crates/ra_ide/src/snapshots/highlight_strings.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/snapshots/highlight_unsafe.html b/crates/ra_ide/src/snapshots/highlight_unsafe.html index 17ffc727cd..bd24e6e381 100644 --- a/crates/ra_ide/src/snapshots/highlight_unsafe.html +++ b/crates/ra_ide/src/snapshots/highlight_unsafe.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } @@ -42,7 +43,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd unsafe { unsafe_fn(); HasUnsafeFn.unsafe_method(); - let y = *x; + let y = *(x); let z = -x; } } \ No newline at end of file diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index 42c5f3e551..e34ff5a7da 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index 2dd61d20d6..1ab06182c0 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -10,7 +10,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 7d946c98da..5bada6252c 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -69,7 +69,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } -.operator.unsafe { color: #E28C14; } +.function.unsafe { color: #BC8383; } +.operator.unsafe { color: #BC8383; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index ba345d90a0..021f8e7e2d 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -274,7 +274,7 @@ fn main() { unsafe { unsafe_fn(); HasUnsafeFn.unsafe_method(); - let y = *x; + let y = *(x); let z = -x; } }