From 2a56323537442958008d0fddd78e33df425b11a9 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 23 Jun 2020 09:17:53 -0400 Subject: Update injection mechanism and stop injecting through highlight element, switch to more general new highlight tag, generic --- crates/ra_ide/src/lib.rs | 4 +- crates/ra_ide/src/prime_caches.rs | 2 +- crates/ra_ide/src/snapshots/highlight_doctest.html | 62 ++++----- .../ra_ide/src/snapshots/highlight_injection.html | 20 +-- crates/ra_ide/src/snapshots/highlight_strings.html | 104 +++++++-------- crates/ra_ide/src/snapshots/highlight_unsafe.html | 28 ++--- crates/ra_ide/src/snapshots/highlighting.html | 140 ++++++++++----------- .../ra_ide/src/snapshots/rainbow_highlighting.html | 20 +-- crates/ra_ide/src/syntax_highlighting.rs | 55 +++++--- crates/ra_ide/src/syntax_highlighting/html.rs | 2 +- crates/ra_ide/src/syntax_highlighting/injection.rs | 12 +- crates/ra_ide/src/syntax_highlighting/tags.rs | 4 +- 12 files changed, 237 insertions(+), 216 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 31bd6cf03..ecac5134e 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, false)) + self.with_db(|db| syntax_highlighting::highlight(db, file_id, None, 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, false) + syntax_highlighting::highlight(db, frange.file_id, Some(frange.range), false) }) } diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs index 59386c5e6..c5ab5a1d8 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, false); + let _ = crate::syntax_highlighting::highlight(db, file, None, false); } } diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html index 95f3d2d1e..e8155def7 100644 --- a/crates/ra_ide/src/snapshots/highlight_doctest.html +++ b/crates/ra_ide/src/snapshots/highlight_doctest.html @@ -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;
+    /// 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
+    /// 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 bc19313d8..1b0349bae 100644 --- a/crates/ra_ide/src/snapshots/highlight_injection.html +++ b/crates/ra_ide/src/snapshots/highlight_injection.html @@ -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 910b2978d..d184b5691 100644 --- a/crates/ra_ide/src/snapshots/highlight_strings.html +++ b/crates/ra_ide/src/snapshots/highlight_strings.html @@ -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 fa986a3bc..6936e949f 100644 --- a/crates/ra_ide/src/snapshots/highlight_unsafe.html +++ b/crates/ra_ide/src/snapshots/highlight_unsafe.html @@ -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 e1852c409..8d0b38f95 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -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 d05a56cf2..9516c7441 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -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 8e714a999..3dffddce5 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -45,7 +45,6 @@ pub(crate) fn highlight( file_id: FileId, range_to_highlight: Option, syntactic_name_ref_highlighting: bool, - should_highlight_punctuation: bool, ) -> Vec { let _p = profile("highlight"); let sema = Semantics::new(db); @@ -108,7 +107,6 @@ pub(crate) fn highlight( &mut bindings_shadow_count, syntactic_name_ref_highlighting, name.syntax().clone().into(), - should_highlight_punctuation, ) { stack.add(HighlightedRange { range: name.syntax().text_range(), @@ -208,7 +206,6 @@ pub(crate) fn highlight( &mut bindings_shadow_count, syntactic_name_ref_highlighting, element_to_highlight.clone(), - true, ) { stack.add(HighlightedRange { range, highlight, binding_hash }); if let Some(string) = @@ -239,7 +236,7 @@ pub(crate) fn highlight( }); } } - stack.pop_and_inject(false); + stack.pop_and_inject(None); } } else if let Some(string) = element_to_highlight.as_token().cloned().and_then(ast::RawString::cast) @@ -327,6 +324,17 @@ impl HighlightedRangeStack { cloned } + /// Remove the `HighlightRange` of `parent` that's currently covered by `child`. + fn intersect_partial(parent: &mut HighlightedRange, child: &HighlightedRange) { + assert!( + parent.range.start() <= child.range.start() + && parent.range.end() >= child.range.start() + && child.range.end() > parent.range.end() + ); + + parent.range = TextRange::new(parent.range.start(), child.range.start()); + } + /// Similar to `pop`, but can modify arbitrary prior ranges (where `pop`) /// can only modify the last range currently on the stack. /// Can be used to do injections that span multiple ranges, like the @@ -336,7 +344,7 @@ impl HighlightedRangeStack { /// /// Note that `pop` can be simulated by `pop_and_inject(false)` but the /// latter is computationally more expensive. - fn pop_and_inject(&mut self, inject: bool) { + fn pop_and_inject(&mut self, overwrite_parent: Option) { let mut children = self.stack.pop().unwrap(); let prev = self.stack.last_mut().unwrap(); children.sort_by_key(|range| range.range.start()); @@ -346,26 +354,41 @@ impl HighlightedRangeStack { if let Some(idx) = prev.iter().position(|parent| parent.range.contains_range(child.range)) { + if let Some(tag) = overwrite_parent { + prev[idx].highlight = tag; + } + let cloned = Self::intersect(&mut prev[idx], &child); - let insert_idx = if inject || prev[idx].range.is_empty() { + let insert_idx = if prev[idx].range.is_empty() { prev.remove(idx); idx } else { idx + 1 }; prev.insert(insert_idx, child); - if !inject && !cloned.range.is_empty() { + if !cloned.range.is_empty() { prev.insert(insert_idx + 1, cloned); } - } else if let Some(_idx) = - prev.iter().position(|parent| parent.range.contains(child.range.start())) - { - unreachable!("child range should be completely contained in parent range"); } else { - let idx = prev - .binary_search_by_key(&child.range.start(), |range| range.range.start()) - .unwrap_or_else(|x| x); - prev.insert(idx, child); + let maybe_idx = + prev.iter().position(|parent| parent.range.contains(child.range.start())); + if let (Some(_), Some(idx)) = (overwrite_parent, maybe_idx) { + Self::intersect_partial(&mut prev[idx], &child); + let insert_idx = if prev[idx].range.is_empty() { + prev.remove(idx); + idx + } else { + idx + 1 + }; + prev.insert(insert_idx, child); + } else if let None = maybe_idx { + let idx = prev + .binary_search_by_key(&child.range.start(), |range| range.range.start()) + .unwrap_or_else(|x| x); + prev.insert(idx, child); + } else { + unreachable!("child range should be completely contained in parent range"); + } } } } @@ -433,7 +456,6 @@ fn highlight_element( bindings_shadow_count: &mut FxHashMap, syntactic_name_ref_highlighting: bool, element: SyntaxElement, - should_highlight_punctuation: bool, ) -> Option<(Highlight, Option)> { let db = sema.db; let mut binding_hash = None; @@ -550,7 +572,6 @@ fn highlight_element( } } - p if should_highlight_punctuation && p.is_punct() => HighlightTag::Punctuation.into(), _ => return None, }; diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 2a27c81dd..0c74f7370 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, false); + let ranges = highlight(db, file_id, None, false); let text = parse.tree().syntax().to_string(); let mut prev_pos = TextSize::from(0); let mut buf = String::new(); diff --git a/crates/ra_ide/src/syntax_highlighting/injection.rs b/crates/ra_ide/src/syntax_highlighting/injection.rs index 8c724af5b..181c21256 100644 --- a/crates/ra_ide/src/syntax_highlighting/injection.rs +++ b/crates/ra_ide/src/syntax_highlighting/injection.rs @@ -8,8 +8,8 @@ use ra_syntax::{ast, AstToken, SyntaxNode, SyntaxToken, TextRange, TextSize}; use stdx::SepBy; use crate::{ - call_info::ActiveParameter, Analysis, HighlightModifier, HighlightTag, HighlightedRange, - RootDatabase, + call_info::ActiveParameter, Analysis, Highlight, HighlightModifier, HighlightTag, + HighlightedRange, RootDatabase, }; use super::HighlightedRangeStack; @@ -150,8 +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, true)).unwrap() - { + for mut h in analysis.with_db(|db| super::highlight(db, tmp_file_id, None, true)).unwrap() { // Determine start offset and end offset in case of multi-line ranges let mut start_offset = None; let mut end_offset = None; @@ -183,6 +182,7 @@ pub(super) fn highlight_doc_comment( for comment in new_comments { stack.add(comment); } - stack.pop_and_inject(false); - stack.pop_and_inject(true); + stack.pop_and_inject(None); + stack + .pop_and_inject(Some(Highlight::from(HighlightTag::Generic) | HighlightModifier::Injected)); } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 7f8e91e8d..e8e251cfc 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -27,13 +27,13 @@ pub enum HighlightTag { Field, FormatSpecifier, Function, + Generic, Keyword, Lifetime, Macro, Module, NumericLiteral, Operator, - Punctuation, SelfKeyword, SelfType, Static, @@ -79,13 +79,13 @@ impl HighlightTag { HighlightTag::Field => "field", HighlightTag::FormatSpecifier => "format_specifier", HighlightTag::Function => "function", + HighlightTag::Generic => "generic", HighlightTag::Keyword => "keyword", HighlightTag::Lifetime => "lifetime", HighlightTag::Macro => "macro", HighlightTag::Module => "module", HighlightTag::NumericLiteral => "numeric_literal", HighlightTag::Operator => "operator", - HighlightTag::Punctuation => "punctuation", HighlightTag::SelfKeyword => "self_keyword", HighlightTag::SelfType => "self_type", HighlightTag::Static => "static", -- cgit v1.2.3