From 56ce34c6a7ec0b4426d4cb25e10512c7efaf6f06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 16:49:46 +0100 Subject: Correctly flag 'lifetime definitions as definitions --- crates/ra_ide/src/snapshots/highlighting.html | 41 +++++++++++----------- .../ra_ide/src/snapshots/rainbow_highlighting.html | 18 +++++----- crates/ra_ide/src/syntax_highlighting.rs | 9 +++-- crates/ra_ide/src/syntax_highlighting/html.rs | 2 +- crates/ra_ide/src/syntax_highlighting/tags.rs | 8 +++-- crates/ra_ide/src/syntax_highlighting/tests.rs | 9 +++-- 6 files changed, 47 insertions(+), 40 deletions(-) diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index cb4097e05..495b07f69 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -3,7 +3,7 @@ body { margin: 0; } pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } - +.lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -27,14 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .control { font-style: italic; }
#[derive(Clone, Debug)]
-struct Foo {
-    pub x: i32,
-    pub y: i32,
+struct Foo {
+    pub x: i32,
+    pub y: i32,
 }
 
-fn foo<T>() -> T {
-    unimplemented!();
-    foo::<i32>();
+fn foo<'a, T>() -> T {
+    foo::<'a, i32>()
 }
 
 macro_rules! def_fn {
@@ -42,40 +41,40 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 }
 
 def_fn! {
-    fn bar() -> u32 {
+    fn bar() -> u32 {
         100
     }
 }
 
 // comment
-fn main() {
+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 { vec.set_len(0); }
 
-    let mut x = 42;
-    let y = &mut x;
-    let z = &y;
+    let mut x = 42;
+    let y = &mut x;
+    let z = &y;
 
     y;
 }
 
-enum Option<T> {
-    Some(T),
-    None,
+enum Option<T> {
+    Some(T),
+    None,
 }
 use Option::*;
 
-impl<T> Option<T> {
-    fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
+impl<T> Option<T> {
+    fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
         match other {
-            None => todo!(),
-            Nope => Nope,
+            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 f63e64b6d..dddbfc0dd 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html @@ -3,7 +3,7 @@ body { margin: 0; } pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } - +.lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } @@ -26,15 +26,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";
+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 6312bcb83..b94b6a022 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -214,8 +214,13 @@ fn highlight_element( INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), BYTE => HighlightTag::ByteLiteral.into(), CHAR => HighlightTag::CharLiteral.into(), - // FIXME: set Declaration for decls - LIFETIME => HighlightTag::Lifetime.into(), + LIFETIME => { + let h = Highlight::new(HighlightTag::Lifetime); + dbg!(match element.parent().map(|it| it.kind()) { + Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition, + _ => h, + }) + } k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 54678c278..e13766c9d 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -80,7 +80,7 @@ const STYLE: &str = " body { margin: 0; } pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } - +.lifetime { color: #DFAF8F; font-style: italic; } .comment { color: #7F9F7F; } .struct, .enum { color: #7CB8BB; } .enum_variant { color: #BDE0F3; } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 9da80823c..8835a5de2 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -90,8 +90,12 @@ impl fmt::Display for HighlightTag { } impl HighlightModifier { - const ALL: &'static [HighlightModifier] = - &[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control]; + const ALL: &'static [HighlightModifier] = &[ + HighlightModifier::Control, + HighlightModifier::Definition, + HighlightModifier::Mutable, + HighlightModifier::Unsafe, + ]; fn as_str(self) -> &'static str { match self { diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 21c4dd818..98c030791 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -17,9 +17,8 @@ struct Foo { pub y: i32, } -fn foo() -> T { - unimplemented!(); - foo::(); +fn foo<'a, T>() -> T { + foo::<'a, i32>() } macro_rules! def_fn { @@ -59,7 +58,7 @@ use Option::*; impl Option { fn and(self, other: Option) -> Option<(T, U)> { match other { - None => todo!(), + None => unimplemented!(), Nope => Nope, } } @@ -130,5 +129,5 @@ fn test_ranges() { .highlight_range(FileRange { file_id, range: TextRange::offset_len(82.into(), 1.into()) }) .unwrap(); - assert_eq!(&highlights[0].highlight.to_string(), "field"); + assert_eq!(&highlights[0].highlight.to_string(), "field.declaration"); } -- cgit v1.2.3