From d8230acd84dc931f72b9dd32b8fbc2aa887d8b4b Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Mon, 22 Jun 2020 10:28:07 -0400 Subject: Add punctuation highlighting for highlighting punctuation in doctests, fix highlighting in doctests --- crates/ra_ide/src/lib.rs | 4 +- crates/ra_ide/src/prime_caches.rs | 2 +- crates/ra_ide/src/snapshots/highlight_doctest.html | 84 ++++++------ .../ra_ide/src/snapshots/highlight_injection.html | 22 ++-- crates/ra_ide/src/snapshots/highlight_strings.html | 106 +++++++-------- crates/ra_ide/src/snapshots/highlight_unsafe.html | 30 ++--- crates/ra_ide/src/snapshots/highlighting.html | 142 ++++++++++----------- .../ra_ide/src/snapshots/rainbow_highlighting.html | 22 ++-- crates/ra_ide/src/syntax_highlighting.rs | 25 ++-- crates/ra_ide/src/syntax_highlighting/html.rs | 4 +- crates/ra_ide/src/syntax_highlighting/injection.rs | 4 +- crates/ra_ide/src/syntax_highlighting/tags.rs | 2 + crates/rust-analyzer/src/semantic_tokens.rs | 5 +- crates/rust-analyzer/src/to_proto.rs | 1 + 14 files changed, 228 insertions(+), 225 deletions(-) diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 22203b4a3..31bd6cf03 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -443,13 +443,13 @@ impl Analysis { /// Computes syntax highlighting for the given file pub fn highlight(&self, file_id: FileId) -> Cancelable> { - self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false, None)) + self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, false, false)) } /// Computes syntax highlighting for the given file range. pub fn highlight_range(&self, frange: FileRange) -> Cancelable> { self.with_db(|db| { - syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false, None) + syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false, false) }) } diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs index dbed8a506..59386c5e6 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}; pub(crate) fn prime_caches(db: &RootDatabase, files: Vec) { for file in files { - let _ = crate::syntax_highlighting::highlight(db, file, None, false, None); + let _ = crate::syntax_highlighting::highlight(db, file, None, false, false); } } diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html index f9a11710e..95f3d2d1e 100644 --- a/crates/ra_ide/src/snapshots/highlight_doctest.html +++ b/crates/ra_ide/src/snapshots/highlight_doctest.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -35,67 +35,67 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .control { font-style: italic; }
/// ```
-/// let _ = "early doctests should not go boom";
-/// ```
-struct Foo {
-    bar: bool,
-}
+/// let _ = "early doctests should not go boom";
+/// ```
+struct Foo {
+    bar: bool,
+}
 
-impl Foo {
-    pub const bar: bool = true;
+impl Foo {
+    pub const bar: bool = true;
 
     /// Constructs a new `Foo`.
     ///
     /// # Examples
     ///
     /// ```
-    /// # #![allow(unused_mut)]
-    /// let mut foo: Foo = Foo::new();
-    /// ```
-    pub const fn new() -> Foo {
-        Foo { bar: true }
-    }
+    /// # #![allow(unused_mut)]
+    /// let mut foo: Foo = Foo::new();
+    /// ```
+    pub const fn new() -> Foo {
+        Foo { bar: true }
+    }
 
     /// `bar` method on `Foo`.
     ///
     /// # Examples
     ///
     /// ```
-    /// use x::y;
-    ///
-    /// let foo = Foo::new();
-    ///
-    /// // calls bar on foo
-    /// assert!(foo.bar());
-    ///
-    /// let bar = foo.bar || Foo::bar;
-    ///
-    /// /* multi-line
-    ///        comment */
-    ///
-    /// let multi_line_string = "Foo
+    /// use x::y;
+    ///
+    /// let foo = Foo::new();
+    ///
+    /// // calls bar on foo
+    /// assert!(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);
-/// ```
-macro_rules! noop {
-    ($expr:expr) => {
-        $expr
-    }
-}
\ No newline at end of file +/// noop!(1); +/// ``` +macro_rules! noop { + ($expr:expr) => { + $expr + } +} \ No newline at end of file diff --git a/crates/ra_ide/src/snapshots/highlight_injection.html b/crates/ra_ide/src/snapshots/highlight_injection.html index 4c3fa2a7b..bc19313d8 100644 --- a/crates/ra_ide/src/snapshots/highlight_injection.html +++ b/crates/ra_ide/src/snapshots/highlight_injection.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -34,14 +34,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
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/ra_ide/src/snapshots/highlight_strings.html b/crates/ra_ide/src/snapshots/highlight_strings.html index 245c425f5..910b2978d 100644 --- a/crates/ra_ide/src/snapshots/highlight_strings.html +++ b/crates/ra_ide/src/snapshots/highlight_strings.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -34,62 +34,62 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
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);
-}
\ No newline at end of file + println!("{\x41}", A = 92); + println!("{ничоси}", ничоси = 92); +}
\ No newline at end of file diff --git a/crates/ra_ide/src/snapshots/highlight_unsafe.html b/crates/ra_ide/src/snapshots/highlight_unsafe.html index fe986b98c..fa986a3bc 100644 --- a/crates/ra_ide/src/snapshots/highlight_unsafe.html +++ b/crates/ra_ide/src/snapshots/highlight_unsafe.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -34,20 +34,20 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
unsafe fn unsafe_fn() {}
+
unsafe fn unsafe_fn() {}
 
-struct HasUnsafeFn;
+struct HasUnsafeFn;
 
-impl HasUnsafeFn {
-    unsafe fn unsafe_method(&self) {}
-}
+impl HasUnsafeFn {
+    unsafe fn unsafe_method(&self) {}
+}
 
-fn main() {
-    let x = &5 as *const usize;
-    unsafe {
-        unsafe_fn();
-        HasUnsafeFn.unsafe_method();
-        let y = *(x);
-        let z = -x;
-    }
-}
\ No newline at end of file +fn main() { + let x = &5 as *const usize; + unsafe { + unsafe_fn(); + HasUnsafeFn.unsafe_method(); + 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 c101af8ea..e1852c409 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -34,84 +34,84 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
#[derive(Clone, Debug)]
-struct Foo {
-    pub x: i32,
-    pub y: i32,
-}
-
-trait Bar {
-    fn bar(&self) -> i32;
-}
-
-impl Bar for Foo {
-    fn bar(&self) -> i32 {
-        self.x
-    }
-}
-
-static mut STATIC_MUT: i32 = 0;
-
-fn foo<'a, T>() -> T {
-    foo::<'a, i32>()
-}
-
-macro_rules! def_fn {
-    ($($tt:tt)*) => {$($tt)*}
-}
-
-def_fn! {
-    fn bar() -> u32 {
+
#[derive(Clone, Debug)]
+struct Foo {
+    pub x: i32,
+    pub y: i32,
+}
+
+trait Bar {
+    fn bar(&self) -> i32;
+}
+
+impl Bar for Foo {
+    fn bar(&self) -> i32 {
+        self.x
+    }
+}
+
+static mut STATIC_MUT: i32 = 0;
+
+fn foo<'a, T>() -> T {
+    foo::<'a, i32>()
+}
+
+macro_rules! def_fn {
+    ($($tt:tt)*) => {$($tt)*}
+}
+
+def_fn! {
+    fn bar() -> u32 {
         100
-    }
-}
+    }
+}
 
-macro_rules! noop {
-    ($expr:expr) => {
-        $expr
-    }
-}
+macro_rules! noop {
+    ($expr:expr) => {
+        $expr
+    }
+}
 
 // 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;
+}
 
-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/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index 97b296d72..d05a56cf2 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -5,7 +5,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -34,15 +34,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
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/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index b4dcdba39..8e714a999 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -45,7 +45,7 @@ pub(crate) fn highlight( file_id: FileId, range_to_highlight: Option, syntactic_name_ref_highlighting: bool, - default_tag: Option, + should_highlight_punctuation: bool, ) -> Vec { let _p = profile("highlight"); let sema = Semantics::new(db); @@ -108,7 +108,7 @@ pub(crate) fn highlight( &mut bindings_shadow_count, syntactic_name_ref_highlighting, name.syntax().clone().into(), - default_tag, + should_highlight_punctuation, ) { stack.add(HighlightedRange { range: name.syntax().text_range(), @@ -208,7 +208,7 @@ pub(crate) fn highlight( &mut bindings_shadow_count, syntactic_name_ref_highlighting, element_to_highlight.clone(), - default_tag, + true, ) { stack.add(HighlightedRange { range, highlight, binding_hash }); if let Some(string) = @@ -331,12 +331,12 @@ impl HighlightedRangeStack { /// can only modify the last range currently on the stack. /// Can be used to do injections that span multiple ranges, like the /// doctest injection below. - /// If `delete` is set to true, the parent range is deleted instead of + /// If `inject` is set to true, the parent range is deleted instead of /// intersected. /// /// Note that `pop` can be simulated by `pop_and_inject(false)` but the /// latter is computationally more expensive. - fn pop_and_inject(&mut self, delete: bool) { + fn pop_and_inject(&mut self, inject: bool) { let mut children = self.stack.pop().unwrap(); let prev = self.stack.last_mut().unwrap(); children.sort_by_key(|range| range.range.start()); @@ -347,14 +347,14 @@ impl HighlightedRangeStack { prev.iter().position(|parent| parent.range.contains_range(child.range)) { let cloned = Self::intersect(&mut prev[idx], &child); - let insert_idx = if delete || prev[idx].range.is_empty() { + let insert_idx = if inject || prev[idx].range.is_empty() { prev.remove(idx); idx } else { idx + 1 }; prev.insert(insert_idx, child); - if !delete && !cloned.range.is_empty() { + if !inject && !cloned.range.is_empty() { prev.insert(insert_idx + 1, cloned); } } else if let Some(_idx) = @@ -433,14 +433,14 @@ fn highlight_element( bindings_shadow_count: &mut FxHashMap, syntactic_name_ref_highlighting: bool, element: SyntaxElement, - default_tag: Option, + should_highlight_punctuation: bool, ) -> Option<(Highlight, Option)> { let db = sema.db; let mut binding_hash = None; let highlight: Highlight = match element.kind() { FN_DEF => { bindings_shadow_count.clear(); - default_tag?.into() + return None; } // Highlight definitions depending on the "type" of the definition. @@ -518,10 +518,10 @@ fn highlight_element( let expr = prefix_expr.expr()?; let ty = sema.type_of_expr(&expr)?; + let mut h = HighlightTag::Operator.into(); if !ty.is_raw_ptr() { - default_tag?.into() + h } else { - let mut h = Highlight::new(HighlightTag::Operator); h |= HighlightModifier::Unsafe; h } @@ -550,7 +550,8 @@ fn highlight_element( } } - _ => default_tag?.into(), + p if should_highlight_punctuation && p.is_punct() => HighlightTag::Punctuation.into(), + _ => return None, }; return Some((highlight, binding_hash)); diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 191c586a3..2a27c81dd 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 ) } - let ranges = highlight(db, file_id, None, false, None); + let ranges = highlight(db, file_id, None, false, false); let text = parse.tree().syntax().to_string(); let mut prev_pos = TextSize::from(0); let mut buf = String::new(); @@ -64,7 +64,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } -.documentation { color: #00CC00; } +.documentation { color: #629755; } .injected { opacity: 0.65 ; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs index bd38cdb6f..8c724af5b 100644 --- a/crates/ra_ide/src/syntax_highlighting/injection.rs +++ b/crates/ra_ide/src/syntax_highlighting/injection.rs @@ -150,9 +150,7 @@ pub(super) fn highlight_doc_comment( let (analysis, tmp_file_id) = Analysis::from_single_file(text); stack.push(); - for mut h in analysis - .with_db(|db| super::highlight(db, tmp_file_id, None, true, Some(HighlightTag::Operator))) - .unwrap() + for mut h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true, true)).unwrap() { // Determine start offset and end offset in case of multi-line ranges let mut start_offset = None; diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index f5ab73865..7f8e91e8d 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -33,6 +33,7 @@ pub enum HighlightTag { Module, NumericLiteral, Operator, + Punctuation, SelfKeyword, SelfType, Static, @@ -84,6 +85,7 @@ impl HighlightTag { HighlightTag::Module => "module", HighlightTag::NumericLiteral => "numeric_literal", HighlightTag::Operator => "operator", + HighlightTag::Punctuation => "punctuation", HighlightTag::SelfKeyword => "self_keyword", HighlightTag::SelfType => "self_type", HighlightTag::Static => "static", diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index 6f43667a3..30f25250f 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -39,13 +39,14 @@ define_semantic_token_types![ (BOOLEAN, "boolean"), (BUILTIN_TYPE, "builtinType"), (ENUM_MEMBER, "enumMember"), + (ESCAPE_SEQUENCE, "escapeSequence"), + (FORMAT_SPECIFIER, "formatSpecifier"), (LIFETIME, "lifetime"), + (PUNCTUATION, "punctuation"), (SELF_KEYWORD, "selfKeyword"), (TYPE_ALIAS, "typeAlias"), (UNION, "union"), (UNRESOLVED_REFERENCE, "unresolvedReference"), - (FORMAT_SPECIFIER, "formatSpecifier"), - (ESCAPE_SEQUENCE, "escapeSequence"), ]; macro_rules! define_semantic_token_modifiers { diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index dee5d7859..efc452347 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -323,6 +323,7 @@ fn semantic_token_type_and_modifiers( HighlightTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE, HighlightTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER, HighlightTag::Operator => lsp_types::SemanticTokenType::OPERATOR, + HighlightTag::Punctuation => semantic_tokens::PUNCTUATION, HighlightTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE, }; -- cgit v1.2.3