From 8ded3ec9cf1b0bf2f08cb849ea969c65c3d497c0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 3 Mar 2022 22:50:43 +0100 Subject: [PATCH] fix: Fix semantic highlighting breaking for lifetimes in macros --- crates/ide/src/syntax_highlighting.rs | 1 + .../test_data/highlight_lifetimes.html | 57 +++++++++++++++++++ crates/ide/src/syntax_highlighting/tests.rs | 24 ++++++++ 3 files changed, 82 insertions(+) create mode 100644 crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 1b2fc9c635d3..59d169661821 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -323,6 +323,7 @@ fn traverse( (T![ident], NAME | NAME_REF) => parent.into(), (T![self] | T![super] | T![crate], NAME_REF) => parent.into(), (INT_NUMBER, NAME_REF) => parent.into(), + (LIFETIME_IDENT, LIFETIME) => parent.into(), _ => token.into(), } } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html b/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html new file mode 100644 index 000000000000..a9fcf8d2b1b2 --- /dev/null +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html @@ -0,0 +1,57 @@ + + +

+#[derive()]
+struct Foo<'a, 'b, 'c> where 'a: 'a, 'static: 'static {
+    field: &'a (),
+    field2: &'static (),
+}
+impl<'a> Foo<'_, 'a, 'static>
+where
+    'a: 'a,
+    'static: 'static
+{
+
+}
+
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index ec50fde3562c..874eaf8cf76a 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -312,6 +312,30 @@ macro_rules! die { ); } +#[test] +fn test_lifetime_highlighting() { + check_highlighting( + r#" +//- minicore: derive + +#[derive()] +struct Foo<'a, 'b, 'c> where 'a: 'a, 'static: 'static { + field: &'a (), + field2: &'static (), +} +impl<'a> Foo<'_, 'a, 'static> +where + 'a: 'a, + 'static: 'static +{ + +} +"#, + expect_file!["./test_data/highlight_lifetimes.html"], + false, + ); +} + #[test] fn test_string_highlighting() { // The format string detection is based on macro-expansion,