From 73bab32aef073a101854099d6ef193737cf2a4fe Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 09:46:50 -0300 Subject: [PATCH 1/9] Highlight more cases of SyntaxKind when it is a punctuation --- crates/ra_ide/src/syntax_highlighting.rs | 46 ++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6ac44c2c02..606637d11b 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -539,21 +539,39 @@ fn highlight_element( _ => h, } } - T![*] => { - let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; - - let expr = prefix_expr.expr()?; - let ty = sema.type_of_expr(&expr)?; - if !ty.is_raw_ptr() { - return None; - } else { - HighlightTag::Operator | HighlightModifier::Unsafe + p if p.is_punct() => match p { + T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), + T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, + T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { + Highlight::new(HighlightTag::Macro) } - } - T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { - Highlight::new(HighlightTag::Macro) - } - p if p.is_punct() => HighlightTag::Punctuation.into(), + T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; + + let expr = prefix_expr.expr()?; + let ty = sema.type_of_expr(&expr)?; + if ty.is_raw_ptr() { + HighlightTag::Operator | HighlightModifier::Unsafe + } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { + HighlightTag::Operator.into() + } else { + HighlightTag::Punctuation.into() + } + } + T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::NumericLiteral.into() + } + _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ => HighlightTag::Punctuation.into(), + }, k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); From 54ebb2ce301813a9b5b48d5abe97ace370cfa617 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 11:21:40 -0300 Subject: [PATCH 2/9] Handle semantic highlight when STAR is part of the `*{const, mut}` --- crates/ra_ide/src/syntax_highlighting.rs | 5 ++- .../ra_ide/test_data/highlight_doctest.html | 14 ++++---- .../ra_ide/test_data/highlight_injection.html | 2 +- .../ra_ide/test_data/highlight_strings.html | 6 ++-- crates/ra_ide/test_data/highlight_unsafe.html | 6 ++-- crates/ra_ide/test_data/highlighting.html | 34 +++++++++---------- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 606637d11b..2b1b6a4fdc 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -543,7 +543,10 @@ fn highlight_element( T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { - Highlight::new(HighlightTag::Macro) + HighlightTag::Macro.into() + } + T![*] if element.parent().and_then(ast::PointerType::cast).is_some() => { + HighlightTag::Keyword.into() } T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; diff --git a/crates/ra_ide/test_data/highlight_doctest.html b/crates/ra_ide/test_data/highlight_doctest.html index 1cc17d6d01..e79e898075 100644 --- a/crates/ra_ide/test_data/highlight_doctest.html +++ b/crates/ra_ide/test_data/highlight_doctest.html @@ -51,9 +51,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// /// ``` /// # #![allow(unused_mut)] - /// let mut foo: Foo = Foo::new(); + /// let mut foo: Foo = Foo::new(); /// ``` - pub const fn new() -> Foo { + pub const fn new() -> Foo { Foo { bar: true } } @@ -62,14 +62,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// # Examples /// /// ``` - /// use x::y; + /// use x::y; /// - /// let foo = Foo::new(); + /// let foo = Foo::new(); /// /// // calls bar on foo /// assert!(foo.bar()); /// - /// let bar = foo.bar || Foo::bar; + /// let bar = foo.bar || Foo::bar; /// /// /* multi-line /// comment */ @@ -81,13 +81,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// ``` /// /// ```rust,no_run - /// let foobar = Foo::new().bar(); + /// let foobar = Foo::new().bar(); /// ``` /// /// ```sh /// echo 1 /// ``` - pub fn foo(&self) -> bool { + pub fn foo(&self) -> bool { true } } diff --git a/crates/ra_ide/test_data/highlight_injection.html b/crates/ra_ide/test_data/highlight_injection.html index 461cfc4377..18addd00d2 100644 --- a/crates/ra_ide/test_data/highlight_injection.html +++ b/crates/ra_ide/test_data/highlight_injection.html @@ -35,7 +35,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
fn fixture(ra_fixture: &str) {}
+
fn fixture(ra_fixture: &str) {}
 
 fn main() {
     fixture(r#"
diff --git a/crates/ra_ide/test_data/highlight_strings.html b/crates/ra_ide/test_data/highlight_strings.html
index 9f98e73e74..258bd404b2 100644
--- a/crates/ra_ide/test_data/highlight_strings.html
+++ b/crates/ra_ide/test_data/highlight_strings.html
@@ -36,14 +36,14 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
 
 
macro_rules! println {
-    ($($arg:tt)*) => ({
-        $crate::io::_print($crate::format_args_nl!($($arg)*));
+    ($($arg:tt)*) => ({
+        $crate::io::_print($crate::format_args_nl!($($arg)*));
     })
 }
 #[rustc_builtin_macro]
 macro_rules! format_args_nl {
     ($fmt:expr) => {{ /* compiler built-in */ }};
-    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
+    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
 }
 
 fn main() {
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index 88ac91f9a0..6c210bfa8b 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -40,15 +40,15 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 struct HasUnsafeFn;
 
 impl HasUnsafeFn {
-    unsafe fn unsafe_method(&self) {}
+    unsafe fn unsafe_method(&self) {}
 }
 
 fn main() {
-    let x = &5 as *const usize;
+    let x = &5 as *const usize;
     unsafe {
         unsafe_fn();
         HasUnsafeFn.unsafe_method();
         let y = *(x);
-        let z = -x;
+        let z = -x;
     }
 }
\ No newline at end of file diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index 767e82f9d0..c49645b0d7 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -42,37 +42,37 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } trait Bar { - fn bar(&self) -> i32; + fn bar(&self) -> i32; } impl Bar for Foo { - fn bar(&self) -> i32 { + fn bar(&self) -> i32 { self.x } } impl Foo { - fn baz(mut self) -> i32 { + fn baz(mut self) -> i32 { self.x } - fn qux(&mut self) { - self.x = 0; + fn qux(&mut self) { + self.x = 0; } } static mut STATIC_MUT: i32 = 0; -fn foo<'a, T>() -> T { - foo::<'a, i32>() +fn foo<'a, T>() -> T { + foo::<'a, i32>() } macro_rules! def_fn { - ($($tt:tt)*) => {$($tt)*} + ($($tt:tt)*) => {$($tt)*} } def_fn! { - fn bar() -> u32 { + fn bar() -> u32 { 100 } } @@ -87,14 +87,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd fn main() { println!("Hello, {}!", 92); - let mut vec = Vec::new(); + let mut vec = Vec::new(); if true { let x = 92; vec.push(Foo { x, y: 1 }); } unsafe { vec.set_len(0); - STATIC_MUT = 1; + STATIC_MUT = 1; } for e in vec { @@ -104,8 +104,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd noop!(noop!(1)); let mut x = 42; - let y = &mut x; - let z = &y; + let y = &mut x; + let z = &y; let Foo { x: z, y } = Foo { x: z, y }; @@ -116,13 +116,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd Some(T), None, } -use Option::*; +use Option::*; impl<T> Option<T> { - fn and<U>(self, other: Option<U>) -> Option<(T, U)> { + fn and<U>(self, other: Option<U>) -> Option<(T, U)> { match other { - None => unimplemented!(), - Nope => Nope, + None => unimplemented!(), + Nope => Nope, } } }
\ No newline at end of file From a662228de41a8b35d61b2bd312d30d34623e2232 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 12:36:23 -0300 Subject: [PATCH 3/9] Assingment semantic highlight --- crates/ra_ide/src/syntax_highlighting.rs | 8 +++++- .../ra_ide/test_data/highlight_doctest.html | 16 +++++------ .../ra_ide/test_data/highlight_strings.html | 28 +++++++++---------- crates/ra_ide/test_data/highlight_unsafe.html | 6 ++-- crates/ra_ide/test_data/highlighting.html | 18 ++++++------ .../test_data/rainbow_highlighting.html | 12 ++++---- 6 files changed, 47 insertions(+), 41 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 2b1b6a4fdc..f088487fa7 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,7 +540,7 @@ fn highlight_element( } } p if p.is_punct() => match p { - T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), + T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] => HighlightTag::Operator.into(), T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { HighlightTag::Macro.into() @@ -573,6 +573,12 @@ fn highlight_element( _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { HighlightTag::Operator.into() } + _ if element.parent().and_then(ast::RangePat::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => { + HighlightTag::Operator.into() + } _ => HighlightTag::Punctuation.into(), }, diff --git a/crates/ra_ide/test_data/highlight_doctest.html b/crates/ra_ide/test_data/highlight_doctest.html index e79e898075..10cb9b20b9 100644 --- a/crates/ra_ide/test_data/highlight_doctest.html +++ b/crates/ra_ide/test_data/highlight_doctest.html @@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
/// ```
-/// let _ = "early doctests should not go boom";
+/// let _ = "early doctests should not go boom";
 /// ```
 struct Foo {
     bar: bool,
 }
 
 impl Foo {
-    pub const bar: bool = true;
+    pub const bar: bool = true;
 
     /// Constructs a new `Foo`.
     ///
@@ -51,7 +51,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     ///
     /// ```
     /// # #![allow(unused_mut)]
-    /// let mut foo: Foo = Foo::new();
+    /// let mut foo: Foo = Foo::new();
     /// ```
     pub const fn new() -> Foo {
         Foo { bar: true }
@@ -64,24 +64,24 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     /// ```
     /// use x::y;
     ///
-    /// let foo = Foo::new();
+    /// let foo = Foo::new();
     ///
     /// // calls bar on foo
     /// assert!(foo.bar());
     ///
-    /// let bar = foo.bar || Foo::bar;
+    /// let bar = foo.bar || Foo::bar;
     ///
     /// /* multi-line
     ///        comment */
     ///
-    /// let multi_line_string = "Foo
+    /// let multi_line_string = "Foo
     ///   bar
     ///          ";
     ///
     /// ```
     ///
     /// ```rust,no_run
-    /// let foobar = Foo::new().bar();
+    /// let foobar = Foo::new().bar();
     /// ```
     ///
     /// ```sh
@@ -96,7 +96,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 /// noop!(1);
 /// ```
 macro_rules! noop {
-    ($expr:expr) => {
+    ($expr:expr) => {
         $expr
     }
 }
\ No newline at end of file diff --git a/crates/ra_ide/test_data/highlight_strings.html b/crates/ra_ide/test_data/highlight_strings.html index 258bd404b2..1b681b2c6b 100644 --- a/crates/ra_ide/test_data/highlight_strings.html +++ b/crates/ra_ide/test_data/highlight_strings.html @@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
macro_rules! println {
-    ($($arg:tt)*) => ({
+    ($($arg:tt)*) => ({
         $crate::io::_print($crate::format_args_nl!($($arg)*));
     })
 }
 #[rustc_builtin_macro]
 macro_rules! format_args_nl {
-    ($fmt:expr) => {{ /* compiler built-in */ }};
-    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
+    ($fmt:expr) => {{ /* compiler built-in */ }};
+    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
 }
 
 fn main() {
@@ -52,18 +52,18 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     println!("Hello, {}!", "world");   // => "Hello, world!"
     println!("The number is {}", 1);   // => "The number is 1"
     println!("{:?}", (3, 4));          // => "(3, 4)"
-    println!("{value}", value=4);      // => "4"
+    println!("{value}", value=4);      // => "4"
     println!("{} {}", 1, 2);           // => "1 2"
     println!("{:04}", 42);             // => "0042" with leading zerosV
     println!("{1} {} {0} {}", 1, 2);   // => "2 1 1 2"
-    println!("{argument}", argument = "test");   // => "test"
-    println!("{name} {}", 1, name = 2);          // => "2 1"
-    println!("{a} {c} {b}", a="a", b='b', c=3);  // => "a 3 b"
+    println!("{argument}", argument = "test");   // => "test"
+    println!("{name} {}", 1, name = 2);          // => "2 1"
+    println!("{a} {c} {b}", a="a", b='b', c=3);  // => "a 3 b"
     println!("{{{}}}", 2);                       // => "{2}"
     println!("Hello {:5}!", "x");
     println!("Hello {:1$}!", "x", 5);
     println!("Hello {1:0$}!", 5, "x");
-    println!("Hello {:width$}!", "x", width = 5);
+    println!("Hello {:width$}!", "x", width = 5);
     println!("Hello {:<5}!", "x");
     println!("Hello {:-<5}!", "x");
     println!("Hello {:^5}!", "x");
@@ -78,10 +78,10 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     println!("Hello {0} is {2:.1$}", "x", 5, 0.01);
     println!("Hello {} is {:.*}",    "x", 5, 0.01);
     println!("Hello {} is {2:.*}",   "x", 5, 0.01);
-    println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
-    println!("{}, `{name:.*}` has 3 fractional digits", "Hello", 3, name=1234.56);
-    println!("{}, `{name:.*}` has 3 characters", "Hello", 3, name="1234.56");
-    println!("{}, `{name:>8.*}` has 3 right-aligned characters", "Hello", 3, name="1234.56");
+    println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
+    println!("{}, `{name:.*}` has 3 fractional digits", "Hello", 3, name=1234.56);
+    println!("{}, `{name:.*}` has 3 characters", "Hello", 3, name="1234.56");
+    println!("{}, `{name:>8.*}` has 3 right-aligned characters", "Hello", 3, name="1234.56");
     println!("Hello {{}}");
     println!("{{ Hello");
 
@@ -91,6 +91,6 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     println!("Hello\nWorld");
     println!("\u{48}\x65\x6C\x6C\x6F World");
 
-    println!("{\x41}", A = 92);
-    println!("{ничоси}", ничоси = 92);
+    println!("{\x41}", A = 92);
+    println!("{ничоси}", ничоси = 92);
 }
\ No newline at end of file diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html index 6c210bfa8b..b81b6f1c3b 100644 --- a/crates/ra_ide/test_data/highlight_unsafe.html +++ b/crates/ra_ide/test_data/highlight_unsafe.html @@ -44,11 +44,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } fn main() { - let x = &5 as *const usize; + let x = &5 as *const usize; unsafe { unsafe_fn(); HasUnsafeFn.unsafe_method(); - let y = *(x); - let z = -x; + let y = *(x); + let z = -x; } }
\ No newline at end of file diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index c49645b0d7..d72efa04a9 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -61,14 +61,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } } -static mut STATIC_MUT: i32 = 0; +static mut STATIC_MUT: i32 = 0; fn foo<'a, T>() -> T { foo::<'a, i32>() } macro_rules! def_fn { - ($($tt:tt)*) => {$($tt)*} + ($($tt:tt)*) => {$($tt)*} } def_fn! { @@ -78,7 +78,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } macro_rules! noop { - ($expr:expr) => { + ($expr:expr) => { $expr } } @@ -87,9 +87,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd fn main() { println!("Hello, {}!", 92); - let mut vec = Vec::new(); + let mut vec = Vec::new(); if true { - let x = 92; + let x = 92; vec.push(Foo { x, y: 1 }); } unsafe { @@ -103,11 +103,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd noop!(noop!(1)); - let mut x = 42; - let y = &mut x; - let z = &y; + let mut x = 42; + let y = &mut x; + let z = &y; - let Foo { x: z, y } = Foo { x: z, y }; + let Foo { x: z, y } = Foo { x: z, y }; y; } diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html index 2fed04a444..08d83302ce 100644 --- a/crates/ra_ide/test_data/rainbow_highlighting.html +++ b/crates/ra_ide/test_data/rainbow_highlighting.html @@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
fn main() {
-    let hello = "hello";
-    let x = hello.to_string();
-    let y = hello.to_string();
+    let hello = "hello";
+    let x = hello.to_string();
+    let y = hello.to_string();
 
-    let x = "other color please!";
-    let y = x.to_string();
+    let x = "other color please!";
+    let y = x.to_string();
 }
 
 fn bar() {
-    let mut hello = "hello";
+    let mut hello = "hello";
 }
\ No newline at end of file From d8eec71dc921a5a20ce9b3abe5251781709fb0db Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 20 Jul 2020 15:37:50 -0400 Subject: [PATCH 4/9] Bump lexer --- Cargo.lock | 4 ++-- crates/ra_syntax/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0ba7b688a..5adbe3947a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1506,9 +1506,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_lexer" -version = "666.0.0" +version = "669.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e00c526f9f8430ea4cd2178d25b02bfc7debe6677350c57292f92f50e65d2fe" +checksum = "456af5f09c006cf6c22c1a433ee0232c4bb74bdc6c647a010166a47c94ed2a63" dependencies = [ "unicode-xid", ] diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 57cc09854b..670f04578a 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml @@ -13,7 +13,7 @@ doctest = false [dependencies] itertools = "0.9.0" rowan = "0.10.0" -rustc_lexer = { version = "666.0.0", package = "rustc-ap-rustc_lexer" } +rustc_lexer = { version = "669.0.0", package = "rustc-ap-rustc_lexer" } rustc-hash = "1.1.0" arrayvec = "0.5.1" once_cell = "1.3.1" From 9cfb373665e25fac5412ac40a97664b82c9176a6 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 20 Jul 2020 15:50:35 -0400 Subject: [PATCH 5/9] Bump chalk --- Cargo.lock | 16 ++++++++-------- crates/ra_hir_ty/Cargo.toml | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e0ba7b688a..46e8282f9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,9 +126,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chalk-derive" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9396f12a23b1a40d5019aa81bc0cbd7ccd2c9736d6bc4afc95868533c2346dcb" +checksum = "eea3a22f0c30b2504ac4ab58934dac0d00b92a4d7788df32795cabca24c3f929" dependencies = [ "proc-macro2", "quote", @@ -138,9 +138,9 @@ dependencies = [ [[package]] name = "chalk-ir" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e9c67d500717d65ede27affb7ae40efe240d86fbefff1006fe0ffb62d4caf9" +checksum = "fb617b643e145e3b151502799e91a9625dd5daf1cf05dc2cb821bc75ae0c9cbd" dependencies = [ "chalk-derive", "lazy_static", @@ -148,9 +148,9 @@ dependencies = [ [[package]] name = "chalk-recursive" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8fd2ac0fc06c857b95614d229bbe8ea317d1d94a7e8b9442a3f05c9a2c2d5f4" +checksum = "d280565c8eefbf9b2bc615df49c7dfd971faad37774bf65734e626fd23864bd6" dependencies = [ "chalk-derive", "chalk-ir", @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a79166f2405c1e51eadcc1344f5ee833c7b391532dd78f64a0731a9a123cc58" +checksum = "be906fbca3f3077dce0e76d9864771d0f450c946af0d86b569fb9504148a065a" dependencies = [ "chalk-derive", "chalk-ir", diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 78f5e55bb8..548a3fc1f4 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -28,9 +28,9 @@ test_utils = { path = "../test_utils" } scoped-tls = "1" -chalk-solve = { version = "0.17.0" } -chalk-ir = { version = "0.17.0" } -chalk-recursive = { version = "0.17.0" } +chalk-solve = { version = "0.18.0" } +chalk-ir = { version = "0.18.0" } +chalk-recursive = { version = "0.18.0" } [dev-dependencies] insta = "0.16.0" From 54cc3fee4550ec7e2e8b6f118de4b7ced546bc97 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 20 Jul 2020 23:50:41 +0300 Subject: [PATCH 6/9] Do not show default types in closures --- crates/ra_hir_ty/src/display.rs | 22 +++++++++++++++++++--- crates/ra_ide/src/inlay_hints.rs | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 758d5f5ac6..19770e609a 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs @@ -257,7 +257,12 @@ impl HirDisplay for ApplicationTy { write!(f, ")")?; let ret = sig.ret(); if *ret != Ty::unit() { - write!(f, " -> {}", ret.display(f.db))?; + let ret_display = if f.omit_verbose_types() { + ret.display_truncated(f.db, f.max_size) + } else { + ret.display(f.db) + }; + write!(f, " -> {}", ret_display)?; } } TypeCtor::FnDef(def) => { @@ -288,7 +293,12 @@ impl HirDisplay for ApplicationTy { write!(f, ")")?; let ret = sig.ret(); if *ret != Ty::unit() { - write!(f, " -> {}", ret.display(f.db))?; + let ret_display = if f.omit_verbose_types() { + ret.display_truncated(f.db, f.max_size) + } else { + ret.display(f.db) + }; + write!(f, " -> {}", ret_display)?; } } TypeCtor::Adt(def_id) => { @@ -397,7 +407,13 @@ impl HirDisplay for ApplicationTy { f.write_joined(sig.params(), ", ")?; write!(f, "|")?; }; - write!(f, " -> {}", sig.ret().display(f.db))?; + + let ret_display = if f.omit_verbose_types() { + sig.ret().display_truncated(f.db, f.max_size) + } else { + sig.ret().display(f.db) + }; + write!(f, " -> {}", ret_display)?; } else { write!(f, "{{closure}}")?; } diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 09883ab4de..f2e4f7ee54 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -425,6 +425,8 @@ fn main() { //^^ Test let zz_ref = &zz; //^^^^^^ &Test + let test = || zz; + //^^^^ || -> Test }"#, ); } From 462e0158dae29cc0c55e699dd0e83c36a60ef5b9 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 23:00:13 -0300 Subject: [PATCH 7/9] @ as operator --- crates/ra_ide/src/syntax_highlighting.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index f088487fa7..0088077cc1 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,8 +540,9 @@ fn highlight_element( } } p if p.is_punct() => match p { - T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] => HighlightTag::Operator.into(), - T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, + T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { + HighlightTag::Operator.into() + } T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { HighlightTag::Macro.into() } From 04d8dc4a10be5e0c6a852011c98284f0121f3293 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 23:19:29 -0300 Subject: [PATCH 8/9] `#` as Attribute - Issue #5453 --- crates/ra_ide/src/syntax_highlighting.rs | 1 + crates/ra_ide/test_data/highlight_doctest.html | 2 +- crates/ra_ide/test_data/highlighting.html | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 0088077cc1..036180c60a 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,6 +540,7 @@ fn highlight_element( } } p if p.is_punct() => match p { + T![#] => HighlightTag::Attribute.into(), T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { HighlightTag::Operator.into() } diff --git a/crates/ra_ide/test_data/highlight_doctest.html b/crates/ra_ide/test_data/highlight_doctest.html index 10cb9b20b9..78c2a30c3d 100644 --- a/crates/ra_ide/test_data/highlight_doctest.html +++ b/crates/ra_ide/test_data/highlight_doctest.html @@ -50,7 +50,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// # Examples /// /// ``` - /// # #![allow(unused_mut)] + /// # #![allow(unused_mut)] /// let mut foo: Foo = Foo::new(); /// ``` pub const fn new() -> Foo { diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index d72efa04a9..182a3817a6 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -35,7 +35,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
#[derive(Clone, Debug)]
+
#[derive(Clone, Debug)]
 struct Foo {
     pub x: i32,
     pub y: i32,

From 5ca3855c06b6e28aaa99f5fdda41b6b80ed871b7 Mon Sep 17 00:00:00 2001
From: GrayJack 
Date: Mon, 20 Jul 2020 23:37:31 -0300
Subject: [PATCH 9/9] On second thought, we want to preserve the textMate here
 where all punctuation that are from a Attr be highlited as Attribute

---
 crates/ra_ide/src/syntax_highlighting.rs       | 4 +++-
 crates/ra_ide/test_data/highlight_doctest.html | 2 +-
 crates/ra_ide/test_data/highlighting.html      | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 036180c60a..d456d5d362 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -540,7 +540,6 @@ fn highlight_element(
             }
         }
         p if p.is_punct() => match p {
-            T![#] => HighlightTag::Attribute.into(),
             T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => {
                 HighlightTag::Operator.into()
             }
@@ -581,6 +580,9 @@ fn highlight_element(
             _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => {
                 HighlightTag::Operator.into()
             }
+            _ if element.parent().and_then(ast::Attr::cast).is_some() => {
+                HighlightTag::Attribute.into()
+            }
             _ => HighlightTag::Punctuation.into(),
         },
 
diff --git a/crates/ra_ide/test_data/highlight_doctest.html b/crates/ra_ide/test_data/highlight_doctest.html
index 78c2a30c3d..6322d404fb 100644
--- a/crates/ra_ide/test_data/highlight_doctest.html
+++ b/crates/ra_ide/test_data/highlight_doctest.html
@@ -50,7 +50,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     /// # Examples
     ///
     /// ```
-    /// # #![allow(unused_mut)]
+    /// # #![allow(unused_mut)]
     /// let mut foo: Foo = Foo::new();
     /// ```
     pub const fn new() -> Foo {
diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html
index 182a3817a6..345a2f0231 100644
--- a/crates/ra_ide/test_data/highlighting.html
+++ b/crates/ra_ide/test_data/highlighting.html
@@ -35,7 +35,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
 
-
#[derive(Clone, Debug)]
+
#[derive(Clone, Debug)]
 struct Foo {
     pub x: i32,
     pub y: i32,