From 73bab32aef073a101854099d6ef193737cf2a4fe Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 09:46:50 -0300 Subject: Highlight more cases of SyntaxKind when it is a punctuation --- crates/ra_ide/src/syntax_highlighting.rs | 46 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6ac44c2c0..606637d11 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -539,21 +539,39 @@ fn highlight_element( _ => h, } } - T![*] => { - let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; - - let expr = prefix_expr.expr()?; - let ty = sema.type_of_expr(&expr)?; - if !ty.is_raw_ptr() { - return None; - } else { - HighlightTag::Operator | HighlightModifier::Unsafe + p if p.is_punct() => match p { + T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), + T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, + T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { + Highlight::new(HighlightTag::Macro) } - } - T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { - Highlight::new(HighlightTag::Macro) - } - p if p.is_punct() => HighlightTag::Punctuation.into(), + T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; + + let expr = prefix_expr.expr()?; + let ty = sema.type_of_expr(&expr)?; + if ty.is_raw_ptr() { + HighlightTag::Operator | HighlightModifier::Unsafe + } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { + HighlightTag::Operator.into() + } else { + HighlightTag::Punctuation.into() + } + } + T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::NumericLiteral.into() + } + _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { + HighlightTag::Operator.into() + } + _ => HighlightTag::Punctuation.into(), + }, k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); -- cgit v1.2.3 From 54ebb2ce301813a9b5b48d5abe97ace370cfa617 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 11:21:40 -0300 Subject: Handle semantic highlight when STAR is part of the `*{const, mut}` --- crates/ra_ide/src/syntax_highlighting.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 606637d11..2b1b6a4fd 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -543,7 +543,10 @@ fn highlight_element( T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { - Highlight::new(HighlightTag::Macro) + HighlightTag::Macro.into() + } + T![*] if element.parent().and_then(ast::PointerType::cast).is_some() => { + HighlightTag::Keyword.into() } T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; -- cgit v1.2.3 From a662228de41a8b35d61b2bd312d30d34623e2232 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 12:36:23 -0300 Subject: Assingment semantic highlight --- crates/ra_ide/src/syntax_highlighting.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 2b1b6a4fd..f088487fa 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,7 +540,7 @@ fn highlight_element( } } p if p.is_punct() => match p { - T![::] | T![->] | T![=>] | T![&] => HighlightTag::Operator.into(), + T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] => HighlightTag::Operator.into(), T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { HighlightTag::Macro.into() @@ -573,6 +573,12 @@ fn highlight_element( _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { HighlightTag::Operator.into() } + _ if element.parent().and_then(ast::RangePat::cast).is_some() => { + HighlightTag::Operator.into() + } + _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => { + HighlightTag::Operator.into() + } _ => HighlightTag::Punctuation.into(), }, -- cgit v1.2.3 From 54cc3fee4550ec7e2e8b6f118de4b7ced546bc97 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 20 Jul 2020 23:50:41 +0300 Subject: Do not show default types in closures --- crates/ra_ide/src/inlay_hints.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 09883ab4d..f2e4f7ee5 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -425,6 +425,8 @@ fn main() { //^^ Test let zz_ref = &zz; //^^^^^^ &Test + let test = || zz; + //^^^^ || -> Test }"#, ); } -- cgit v1.2.3 From 462e0158dae29cc0c55e699dd0e83c36a60ef5b9 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 23:00:13 -0300 Subject: @ as operator --- crates/ra_ide/src/syntax_highlighting.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index f088487fa..0088077cc 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,8 +540,9 @@ fn highlight_element( } } p if p.is_punct() => match p { - T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] => HighlightTag::Operator.into(), - T![@] => HighlightTag::Operator | HighlightModifier::ControlFlow, + T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { + HighlightTag::Operator.into() + } T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { HighlightTag::Macro.into() } -- cgit v1.2.3 From 04d8dc4a10be5e0c6a852011c98284f0121f3293 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 23:19:29 -0300 Subject: `#` as Attribute - Issue #5453 --- crates/ra_ide/src/syntax_highlighting.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 0088077cc..036180c60 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,6 +540,7 @@ fn highlight_element( } } p if p.is_punct() => match p { + T![#] => HighlightTag::Attribute.into(), T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { HighlightTag::Operator.into() } -- cgit v1.2.3 From 5ca3855c06b6e28aaa99f5fdda41b6b80ed871b7 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 20 Jul 2020 23:37:31 -0300 Subject: On second thought, we want to preserve the textMate here where all punctuation that are from a Attr be highlited as Attribute --- crates/ra_ide/src/syntax_highlighting.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 036180c60..d456d5d36 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -540,7 +540,6 @@ fn highlight_element( } } p if p.is_punct() => match p { - T![#] => HighlightTag::Attribute.into(), T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { HighlightTag::Operator.into() } @@ -581,6 +580,9 @@ fn highlight_element( _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => { HighlightTag::Operator.into() } + _ if element.parent().and_then(ast::Attr::cast).is_some() => { + HighlightTag::Attribute.into() + } _ => HighlightTag::Punctuation.into(), }, -- cgit v1.2.3