From 78fe6133c4908aefcf5c690e665abba9ef2389eb Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 10 Jan 2021 13:33:03 +0100 Subject: Split punctuation semantic highlighting up into more tags --- crates/ide/src/lib.rs | 2 +- crates/ide/src/syntax_highlighting/highlight.rs | 17 +- crates/ide/src/syntax_highlighting/tags.rs | 36 ++- .../test_data/highlight_assoc_functions.html | 28 +-- .../test_data/highlight_doctest.html | 52 ++--- .../test_data/highlight_extern_crate.html | 4 +- .../test_data/highlight_injection.html | 20 +- .../test_data/highlight_strings.html | 106 ++++----- .../test_data/highlight_unsafe.html | 88 +++---- .../test_data/highlighting.html | 260 ++++++++++----------- .../syntax_highlighting/test_data/injection.html | 16 +- .../test_data/rainbow_highlighting.html | 20 +- crates/rust-analyzer/src/semantic_tokens.rs | 8 + crates/rust-analyzer/src/to_proto.rs | 18 +- 14 files changed, 368 insertions(+), 307 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 409507bd0..1f368cbd0 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -76,7 +76,7 @@ pub use crate::{ references::{rename::RenameError, Declaration, ReferenceSearchResult}, runnables::{Runnable, RunnableKind, TestId}, syntax_highlighting::{ - tags::{Highlight, HlMod, HlMods, HlTag}, + tags::{Highlight, HlMod, HlMods, HlPunct, HlTag}, HlRange, }, }; diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 1a88975d2..0cb58d589 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -12,7 +12,7 @@ use syntax::{ SyntaxNode, SyntaxToken, T, }; -use crate::{Highlight, HlMod, HlTag, SymbolKind}; +use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind}; pub(super) fn element( sema: &Semantics, @@ -173,7 +173,7 @@ pub(super) fn element( } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { HlTag::Operator.into() } else { - HlTag::Punctuation.into() + HlTag::Punctuation(HlPunct::Other).into() } } T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { @@ -196,7 +196,18 @@ pub(super) fn element( _ if element.parent().and_then(ast::RangePat::cast).is_some() => HlTag::Operator.into(), _ if element.parent().and_then(ast::RestPat::cast).is_some() => HlTag::Operator.into(), _ if element.parent().and_then(ast::Attr::cast).is_some() => HlTag::Attribute.into(), - _ => HlTag::Punctuation.into(), + kind => HlTag::Punctuation(match kind { + T!['['] | T![']'] => HlPunct::Bracket, + T!['{'] | T!['}'] => HlPunct::Brace, + T!['('] | T![')'] => HlPunct::Parenthesis, + T![<] | T![>] => HlPunct::Angle, + T![,] => HlPunct::Comma, + T![:] => HlPunct::Colon, + T![;] => HlPunct::Semi, + T![.] => HlPunct::Dot, + _ => HlPunct::Other, + }) + .into(), }, k if k.is_keyword() => { diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 2f39bcc8e..a4396e790 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -29,7 +29,7 @@ pub enum HlTag { EscapeSequence, FormatSpecifier, Keyword, - Punctuation, + Punctuation(HlPunct), Operator, UnresolvedReference, @@ -61,6 +61,28 @@ pub enum HlMod { Unsafe, } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum HlPunct { + /// [] + Bracket, + /// {} + Brace, + /// () + Parenthesis, + /// <> + Angle, + /// , + Comma, + /// . + Dot, + /// : + Colon, + /// ; + Semi, + /// + Other, +} + impl HlTag { fn as_str(self) -> &'static str { match self { @@ -95,7 +117,17 @@ impl HlTag { HlTag::EscapeSequence => "escape_sequence", HlTag::FormatSpecifier => "format_specifier", HlTag::Keyword => "keyword", - HlTag::Punctuation => "punctuation", + HlTag::Punctuation(punct) => match punct { + HlPunct::Bracket => "bracket", + HlPunct::Brace => "brace", + HlPunct::Parenthesis => "parentheses", + HlPunct::Angle => "angle", + HlPunct::Comma => "comma", + HlPunct::Dot => "dot", + HlPunct::Colon => "colon", + HlPunct::Semi => "semicolon", + HlPunct::Other => "punctuation", + }, HlTag::NumericLiteral => "numeric_literal", HlTag::Operator => "operator", HlTag::StringLiteral => "string_literal", diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index 506ebe60e..d4e7b45be 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html @@ -36,22 +36,22 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
fn not_static() {}
+
fn not_static() {}
 
-struct foo {}
+struct foo {}
 
-impl foo {
-    pub fn is_static() {}
-    pub fn is_not_static(&self) {}
-}
+impl foo {
+    pub fn is_static() {}
+    pub fn is_not_static(&self) {}
+}
 
-trait t {
-    fn t_is_static() {}
-    fn t_is_not_static(&self) {}
-}
+trait t {
+    fn t_is_static() {}
+    fn t_is_not_static(&self) {}
+}
 
-impl t for foo {
-    pub fn is_static() {}
-    pub fn is_not_static(&self) {}
-}
+impl t for foo {
+    pub fn is_static() {}
+    pub fn is_not_static(&self) {}
+}
         
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 7d1d2a839..df0cf3704 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -37,72 +37,72 @@ 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,
-}
+struct Foo {
+    bar: bool,
+}
 
-impl Foo {
+impl Foo {
     /// ```
     /// let _ = "Call me
     //    KILLER WHALE
-    ///     Ishmael.";
+    ///     Ishmael.";
     /// ```
-    pub const bar: bool = true;
+    pub const bar: bool = true;
 
     /// Constructs a new `Foo`.
     ///
     /// # Examples
     ///
     /// ```
-    /// # #![allow(unused_mut)]
-    /// let mut foo: Foo = Foo::new();
+    /// # #![allow(unused_mut)]
+    /// let mut foo: Foo = Foo::new();
     /// ```
-    pub const fn new() -> Foo {
-        Foo { bar: true }
-    }
+    pub const fn new() -> Foo {
+        Foo { bar: true }
+    }
 
     /// `bar` method on `Foo`.
     ///
     /// # Examples
     ///
     /// ```
-    /// use x::y;
+    /// use x::y;
     ///
-    /// let foo = Foo::new();
+    /// let foo = Foo::new();
     ///
     /// // calls bar on foo
-    /// assert!(foo.bar());
+    /// assert!(foo.bar());
     ///
-    /// let bar = foo.bar || Foo::bar;
+    /// let bar = foo.bar || Foo::bar;
     ///
     /// /* multi-line
     ///        comment */
     ///
     /// let multi_line_string = "Foo
     ///   bar
-    ///          ";
+    ///          ";
     ///
     /// ```
     ///
     /// ```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
-    }
-}
+    }
+}
 
 /// ```
-/// noop!(1);
+/// noop!(1);
 /// ```
-macro_rules! noop {
-    ($expr:expr) => {
+macro_rules! noop {
+    ($expr:expr) => {
         $expr
-    }
-}
\ No newline at end of file + } +}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index ed452586a..6f7a7ffff 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html @@ -36,6 +36,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
extern crate std;
-extern crate alloc as abc;
+
extern crate std;
+extern crate alloc as abc;
 
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 92e7dc3e4..169c268f5 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html @@ -36,14 +36,14 @@ 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#"
-        trait Foo {
-            fn foo() {
-                println!("2 + 2 = {}", 4);
-            }
-        }"#
-    );
-}
\ No newline at end of file +fn main() { + fixture(r#" + trait Foo { + fn foo() { + println!("2 + 2 = {}", 4); + } + }"# + ); +}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 31dad5d42..d8626c8bc 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -36,64 +36,64 @@ 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)*));
-    })
-}
+
macro_rules! println {
+    ($($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 */ }};
-}
+macro_rules! format_args_nl {
+    ($fmt:expr) => {{ /* compiler built-in */ }};
+    ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
+}
 
-fn main() {
+fn main() {
     // from https://doc.rust-lang.org/std/fmt/index.html
-    println!("Hello");                 // => "Hello"
-    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!("{} {}", 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!("{{{}}}", 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 {:<5}!", "x");
-    println!("Hello {:-<5}!", "x");
-    println!("Hello {:^5}!", "x");
-    println!("Hello {:>5}!", "x");
-    println!("Hello {:+}!", 5);
-    println!("{:#x}!", 27);
-    println!("Hello {:05}!", 5);
-    println!("Hello {:05}!", -5);
-    println!("{:#010x}!", 27);
-    println!("Hello {0} is {1:.5}", "x", 0.01);
-    println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
-    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 {{}}");
-    println!("{{ Hello");
+    println!("Hello");                 // => "Hello"
+    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!("{} {}", 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!("{{{}}}", 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 {:<5}!", "x");
+    println!("Hello {:-<5}!", "x");
+    println!("Hello {:^5}!", "x");
+    println!("Hello {:>5}!", "x");
+    println!("Hello {:+}!", 5);
+    println!("{:#x}!", 27);
+    println!("Hello {:05}!", 5);
+    println!("Hello {:05}!", -5);
+    println!("{:#010x}!", 27);
+    println!("Hello {0} is {1:.5}", "x", 0.01);
+    println!("Hello {1} is {2:.0$}", 5, "x", 0.01);
+    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 {{}}");
+    println!("{{ Hello");
 
-    println!(r"Hello, {}!", "world");
+    println!(r"Hello, {}!", "world");
 
     // escape sequences
-    println!("Hello\nWorld");
-    println!("\u{48}\x65\x6C\x6C\x6F World");
+    println!("Hello\nWorld");
+    println!("\u{48}\x65\x6C\x6C\x6F World");
 
-    println!("{\x41}", A = 92);
-    println!("{ничоси}", ничоси = 92);
+    println!("{\x41}", A = 92);
+    println!("{ничоси}", ничоси = 92);
 
-    println!("{:x?} {} ", thingy, n2);
-}
\ No newline at end of file + println!("{:x?} {} ", thingy, n2); +}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index e3a0aa317..56a4380fb 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -36,65 +36,65 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
unsafe fn unsafe_fn() {}
+
unsafe fn unsafe_fn() {}
 
-union Union {
-    a: u32,
-    b: f32,
-}
+union Union {
+    a: u32,
+    b: f32,
+}
 
-struct HasUnsafeFn;
+struct HasUnsafeFn;
 
-impl HasUnsafeFn {
-    unsafe fn unsafe_method(&self) {}
-}
+impl HasUnsafeFn {
+    unsafe fn unsafe_method(&self) {}
+}
 
-struct TypeForStaticMut {
-    a: u8
-}
+struct TypeForStaticMut {
+    a: u8
+}
 
-static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
+static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
 
-#[repr(packed)]
-struct Packed {
-    a: u16,
-}
+#[repr(packed)]
+struct Packed {
+    a: u16,
+}
 
-trait DoTheAutoref {
-    fn calls_autoref(&self);
-}
+trait DoTheAutoref {
+    fn calls_autoref(&self);
+}
 
-impl DoTheAutoref for u16 {
-    fn calls_autoref(&self) {}
-}
+impl DoTheAutoref for u16 {
+    fn calls_autoref(&self) {}
+}
 
-fn main() {
-    let x = &5 as *const _ as *const usize;
-    let u = Union { b: 0 };
-    unsafe {
+fn main() {
+    let x = &5 as *const _ as *const usize;
+    let u = Union { b: 0 };
+    unsafe {
         // unsafe fn and method calls
-        unsafe_fn();
-        let b = u.b;
-        match u {
-            Union { b: 0 } => (),
-            Union { a } => (),
-        }
-        HasUnsafeFn.unsafe_method();
+        unsafe_fn();
+        let b = u.b;
+        match u {
+            Union { b: 0 } => (),
+            Union { a } => (),
+        }
+        HasUnsafeFn.unsafe_method();
 
         // unsafe deref
-        let y = *x;
+        let y = *x;
 
         // unsafe access to a static mut
-        let a = global_mut.a;
+        let a = global_mut.a;
 
         // unsafe ref of packed fields
-        let packed = Packed { a: 0 };
-        let a = &packed.a;
-        let ref a = packed.a;
-        let Packed { ref a } = packed;
-        let Packed { a: ref _a } = packed;
+        let packed = Packed { a: 0 };
+        let a = &packed.a;
+        let ref a = packed.a;
+        let Packed { ref a } = packed;
+        let Packed { a: ref _a } = packed;
 
         // unsafe auto ref of packed field
-        packed.a.calls_autoref();
-    }
-}
\ No newline at end of file + packed.a.calls_autoref(); + } +}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 02270b077..b7bec083b 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html @@ -36,187 +36,187 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
use inner::{self as inner_mod};
-mod inner {}
+
use inner::{self as inner_mod};
+mod inner {}
 
 #[rustc_builtin_macro]
-macro Copy {}
+macro Copy {}
 
 // Needed for function consuming vs normal
-pub mod marker {
+pub mod marker {
     #[lang = "copy"]
-    pub trait Copy {}
-}
+    pub trait Copy {}
+}
 
-pub mod ops {
+pub mod ops {
     #[lang = "fn_once"]
-    pub trait FnOnce<Args> {}
+    pub trait FnOnce<Args> {}
 
     #[lang = "fn_mut"]
-    pub trait FnMut<Args>: FnOnce<Args> {}
+    pub trait FnMut<Args>: FnOnce<Args> {}
 
     #[lang = "fn"]
-    pub trait Fn<Args>: FnMut<Args> {}
-}
+    pub trait Fn<Args>: FnMut<Args> {}
+}
 
 
-struct Foo {
-    pub x: i32,
-    pub y: i32,
-}
+struct Foo {
+    pub x: i32,
+    pub y: i32,
+}
 
-trait Bar {
-    fn bar(&self) -> i32;
-}
+trait Bar {
+    fn bar(&self) -> i32;
+}
 
-impl Bar for Foo {
-    fn bar(&self) -> i32 {
+impl Bar for Foo {
+    fn bar(&self) -> i32 {
         self.x
-    }
-}
+    }
+}
 
-impl Foo {
-    fn baz(mut self, f: Foo) -> i32 {
-        f.baz(self)
-    }
+impl Foo {
+    fn baz(mut self, f: Foo) -> i32 {
+        f.baz(self)
+    }
 
-    fn qux(&mut self) {
-        self.x = 0;
-    }
+    fn qux(&mut self) {
+        self.x = 0;
+    }
 
-    fn quop(&self) -> i32 {
+    fn quop(&self) -> i32 {
         self.x
-    }
-}
+    }
+}
 
-#[derive(Copy)]
-struct FooCopy {
-    x: u32,
-}
+#[derive(Copy)]
+struct FooCopy {
+    x: u32,
+}
 
-impl FooCopy {
-    fn baz(self, f: FooCopy) -> u32 {
-        f.baz(self)
-    }
+impl FooCopy {
+    fn baz(self, f: FooCopy) -> u32 {
+        f.baz(self)
+    }
 
-    fn qux(&mut self) {
-        self.x = 0;
-    }
+    fn qux(&mut self) {
+        self.x = 0;
+    }
 
-    fn quop(&self) -> u32 {
+    fn quop(&self) -> u32 {
         self.x
-    }
-}
+    }
+}
 
-static mut STATIC_MUT: i32 = 0;
+static mut STATIC_MUT: i32 = 0;
 
-fn foo<'a, T>() -> T {
-    foo::<'a, i32>()
-}
+fn foo<'a, T>() -> T {
+    foo::<'a, i32>()
+}
 
-fn never() -> ! {
-    loop {}
-}
+fn never() -> ! {
+    loop {}
+}
 
-fn const_param<const FOO: usize>() -> usize {
+fn const_param<const FOO: usize>() -> usize {
     FOO
-}
+}
 
-use ops::Fn;
-fn baz<F: Fn() -> ()>(f: F) {
-    f()
-}
+use ops::Fn;
+fn baz<F: Fn() -> ()>(f: F) {
+    f()
+}
 
-fn foobar() -> impl Copy {}
+fn foobar() -> impl Copy {}
 
-fn foo() {
-    let bar = foobar();
-}
+fn foo() {
+    let bar = foobar();
+}
 
-macro_rules! def_fn {
-    ($($tt:tt)*) => {$($tt)*}
-}
+macro_rules! def_fn {
+    ($($tt:tt)*) => {$($tt)*}
+}
 
-def_fn! {
-    fn bar() -> u32 {
+def_fn! {
+    fn bar() -> u32 {
         100
-    }
-}
+    }
+}
 
-macro_rules! noop {
-    ($expr:expr) => {
+macro_rules! noop {
+    ($expr:expr) => {
         $expr
-    }
-}
+    }
+}
 
-macro_rules! keyword_frag {
-    ($type:ty) => ($type)
-}
+macro_rules! keyword_frag {
+    ($type:ty) => ($type)
+}
 
 // comment
-fn main() {
-    println!("Hello, {}!", 92);
-
-    let mut vec = Vec::new();
-    if true {
-        let x = 92;
-        vec.push(Foo { x, y: 1 });
-    }
-    unsafe {
-        vec.set_len(0);
-        STATIC_MUT = 1;
-    }
-
-    for e in vec {
+fn main() {
+    println!("Hello, {}!", 92);
+
+    let mut vec = Vec::new();
+    if true {
+        let x = 92;
+        vec.push(Foo { x, y: 1 });
+    }
+    unsafe {
+        vec.set_len(0);
+        STATIC_MUT = 1;
+    }
+
+    for e in vec {
         // Do nothing
-    }
+    }
 
-    noop!(noop!(1));
+    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;
+    y;
 
-    let mut foo = Foo { x, y: x };
-    let foo2 = Foo { x, y: x };
-    foo.quop();
-    foo.qux();
-    foo.baz(foo2);
+    let mut foo = Foo { x, y: x };
+    let foo2 = Foo { x, y: x };
+    foo.quop();
+    foo.qux();
+    foo.baz(foo2);
 
-    let mut copy = FooCopy { x };
-    copy.quop();
-    copy.qux();
-    copy.baz(copy);
+    let mut copy = FooCopy { x };
+    copy.quop();
+    copy.qux();
+    copy.baz(copy);
 
-    let a = |x| x;
-    let bar = Foo::baz;
+    let a = |x| x;
+    let bar = Foo::baz;
 
-    let baz = -42;
-    let baz = -baz;
+    let baz = -42;
+    let baz = -baz;
 
-    let _ = !true;
+    let _ = !true;
 
-    'foo: loop {
-        break 'foo;
-        continue 'foo;
-    }
-}
+    'foo: loop {
+        break 'foo;
+        continue 'foo;
+    }
+}
 
-enum Option<T> {
-    Some(T),
-    None,
-}
-use Option::*;
+enum Option<T> {
+    Some(T),
+    None,
+}
+use Option::*;
 
-impl<T> Option<T> {
-    fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
-        match other {
-            None => unimplemented!(),
-            Nope => Nope,
-        }
-    }
-}
\ No newline at end of file +impl<T> Option<T> { + fn and<U>(self, other: Option<U>) -> Option<(T, U)> { + match other { + None => unimplemented!(), + Nope => Nope, + } + } +}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/injection.html b/crates/ide/src/syntax_highlighting/test_data/injection.html index 6703a84e5..52fabd180 100644 --- a/crates/ide/src/syntax_highlighting/test_data/injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/injection.html @@ -36,13 +36,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
fn f(ra_fixture: &str) {}
-fn main() {
-    f(r"
-fn foo() {
-    foo($0{
+
fn f(ra_fixture: &str) {}
+fn main() {
+    f(r"
+fn foo() {
+    foo($0{
         92
-    }$0)
-}");
-}
+    }$0)
+}");
+}
     
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html index 8b3dfa69f..196c898f7 100644 --- a/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/rainbow_highlighting.html @@ -36,15 +36,15 @@ 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();
+
fn main() {
+    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";
-}
\ No newline at end of file +fn bar() { + let mut hello = "hello"; +}
\ No newline at end of file diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index 5c4366f16..7ce9a4ab6 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -38,17 +38,25 @@ macro_rules! define_semantic_token_types { } define_semantic_token_types![ + (ANGLE, "angle"), (ATTRIBUTE, "attribute"), (BOOLEAN, "boolean"), + (BRACE, "brace"), + (BRACKET, "bracket"), (BUILTIN_TYPE, "builtinType"), + (COMMA, "comma"), + (COLON, "colon"), + (DOT, "dot"), (ESCAPE_SEQUENCE, "escapeSequence"), (FORMAT_SPECIFIER, "formatSpecifier"), (GENERIC, "generic"), (CONST_PARAMETER, "constParameter"), (LIFETIME, "lifetime"), (LABEL, "label"), + (PARENTHESIS, "parenthesis"), (PUNCTUATION, "punctuation"), (SELF_KEYWORD, "selfKeyword"), + (SEMICOLON, "semicolon"), (TYPE_ALIAS, "typeAlias"), (UNION, "union"), (UNRESOLVED_REFERENCE, "unresolvedReference"), diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index d6bf60cde..bdddca9da 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -6,9 +6,9 @@ use std::{ use ide::{ Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId, - FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlRange, HlTag, Indel, InlayHint, - InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess, Runnable, - Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize, + FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel, + InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess, + Runnable, Severity, SourceChange, SourceFileEdit, SymbolKind, TextEdit, TextRange, TextSize, }; use itertools::Itertools; @@ -423,7 +423,17 @@ fn semantic_token_type_and_modifiers( HlTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER, HlTag::Operator => lsp_types::SemanticTokenType::OPERATOR, HlTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE, - HlTag::Punctuation => semantic_tokens::PUNCTUATION, + HlTag::Punctuation(punct) => match punct { + HlPunct::Bracket => semantic_tokens::BRACKET, + HlPunct::Brace => semantic_tokens::BRACE, + HlPunct::Parenthesis => semantic_tokens::PARENTHESIS, + HlPunct::Angle => semantic_tokens::ANGLE, + HlPunct::Comma => semantic_tokens::COMMA, + HlPunct::Dot => semantic_tokens::DOT, + HlPunct::Colon => semantic_tokens::COLON, + HlPunct::Semi => semantic_tokens::SEMICOLON, + HlPunct::Other => semantic_tokens::PUNCTUATION, + }, }; for modifier in highlight.mods.iter() { -- cgit v1.2.3