From 47ce5ea581f3fe53a31e166c5feac6c64a8a97e4 Mon Sep 17 00:00:00 2001 From: George Fraser Date: Tue, 12 May 2020 21:58:51 -0700 Subject: Color attribute functions --- crates/ra_ide/src/syntax_highlighting/tags.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index be1a0f12b..33e6619ec 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -45,8 +45,10 @@ pub enum HighlightTag { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] #[repr(u8)] pub enum HighlightModifier { + /// Used to differentiate individual elements within attributes. + Attribute = 0, /// Used with keywords like `if` and `break`. - ControlFlow = 0, + ControlFlow, /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is /// not. Definition, @@ -95,6 +97,7 @@ impl fmt::Display for HighlightTag { impl HighlightModifier { const ALL: &'static [HighlightModifier] = &[ + HighlightModifier::Attribute, HighlightModifier::ControlFlow, HighlightModifier::Definition, HighlightModifier::Mutable, @@ -103,6 +106,7 @@ impl HighlightModifier { fn as_str(self) -> &'static str { match self { + HighlightModifier::Attribute => "attribute", HighlightModifier::ControlFlow => "control", HighlightModifier::Definition => "declaration", HighlightModifier::Mutable => "mutable", -- cgit v1.2.3 From e2d36cb692f042f2051a8a88d271a297a3d333a4 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 21 May 2020 17:40:52 +0100 Subject: Highlight `true` and `false` as literals --- crates/ra_ide/src/syntax_highlighting/html.rs | 1 + crates/ra_ide/src/syntax_highlighting/tags.rs | 2 ++ 2 files changed, 3 insertions(+) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index ff0eeeb52..edfe61f39 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -76,6 +76,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .type_param { color: #DFAF8F; } .attribute { color: #94BFF3; } .numeric_literal { color: #BFEBBF; } +.bool_literal { color: #BFE6EB; } .macro { color: #94BFF3; } .module { color: #AFD8AF; } .variable { color: #DCDCCC; } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 33e6619ec..09652a5b1 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -15,6 +15,7 @@ pub struct HighlightModifiers(u32); #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum HighlightTag { Attribute, + BoolLiteral, BuiltinType, ByteLiteral, CharLiteral, @@ -60,6 +61,7 @@ impl HighlightTag { fn as_str(self) -> &'static str { match self { HighlightTag::Attribute => "attribute", + HighlightTag::BoolLiteral => "bool_literal", HighlightTag::BuiltinType => "builtin_type", HighlightTag::ByteLiteral => "byte_literal", HighlightTag::CharLiteral => "char_literal", -- cgit v1.2.3 From c2358365ad0b82d4a5f023192ee0ab2c198d6aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 25 May 2020 11:51:56 +0300 Subject: Add self keyword semantic token type --- crates/ra_ide/src/syntax_highlighting/tags.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 09652a5b1..46c718c91 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -30,6 +30,7 @@ pub enum HighlightTag { Macro, Module, NumericLiteral, + SelfKeyword, SelfType, Static, StringLiteral, @@ -76,6 +77,7 @@ impl HighlightTag { HighlightTag::Macro => "macro", HighlightTag::Module => "module", HighlightTag::NumericLiteral => "numeric_literal", + HighlightTag::SelfKeyword => "self_keyword", HighlightTag::SelfType => "self_type", HighlightTag::Static => "static", HighlightTag::StringLiteral => "string_literal", -- cgit v1.2.3 From 18aa4bcb0328393db0c20de0241e1e9606901144 Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Fri, 29 May 2020 21:17:14 +0200 Subject: Add semantic highlight to QUESTION token Made it an operator with controlFlow modifier. --- crates/ra_ide/src/syntax_highlighting/tags.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 46c718c91..1514531de 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -42,6 +42,7 @@ pub enum HighlightTag { Local, UnresolvedReference, FormatSpecifier, + Operator, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -89,6 +90,7 @@ impl HighlightTag { HighlightTag::Local => "variable", HighlightTag::UnresolvedReference => "unresolved_reference", HighlightTag::FormatSpecifier => "format_specifier", + HighlightTag::Operator => "operator", } } } -- cgit v1.2.3 From 780c89959a2f7362eb51508d83863eeff9a49e4c Mon Sep 17 00:00:00 2001 From: Roland Ruckerbauer Date: Sat, 30 May 2020 18:35:11 +0200 Subject: Test case for format string highlighting of closing curlybrace --- crates/ra_ide/src/syntax_highlighting/tests.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index eb43a23da..7dc229cab 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -218,6 +218,7 @@ fn main() { 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"); -- cgit v1.2.3 From a9cb2933fbeddef4ed70bde77ded4f9bb185548e Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 2 Jun 2020 18:49:09 -0400 Subject: Add highlight support for unsafe fn calls and raw ptr deref --- crates/ra_ide/src/syntax_highlighting/html.rs | 1 + crates/ra_ide/src/syntax_highlighting/tags.rs | 8 +++---- crates/ra_ide/src/syntax_highlighting/tests.rs | 31 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/syntax_highlighting') diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index edfe61f39..7d946c98d 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -69,6 +69,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .string_literal { color: #CC9393; } .field { color: #94BFF3; } .function { color: #93E0E3; } +.operator.unsafe { color: #E28C14; } .parameter { color: #94BFF3; } .text { color: #DCDCCC; } .type { color: #7CB8BB; } diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 1514531de..94f466966 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -24,12 +24,14 @@ pub enum HighlightTag { Enum, EnumVariant, Field, + FormatSpecifier, Function, Keyword, Lifetime, Macro, Module, NumericLiteral, + Operator, SelfKeyword, SelfType, Static, @@ -41,8 +43,6 @@ pub enum HighlightTag { Union, Local, UnresolvedReference, - FormatSpecifier, - Operator, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -72,12 +72,14 @@ impl HighlightTag { HighlightTag::Enum => "enum", HighlightTag::EnumVariant => "enum_variant", HighlightTag::Field => "field", + HighlightTag::FormatSpecifier => "format_specifier", HighlightTag::Function => "function", HighlightTag::Keyword => "keyword", HighlightTag::Lifetime => "lifetime", HighlightTag::Macro => "macro", HighlightTag::Module => "module", HighlightTag::NumericLiteral => "numeric_literal", + HighlightTag::Operator => "operator", HighlightTag::SelfKeyword => "self_keyword", HighlightTag::SelfType => "self_type", HighlightTag::Static => "static", @@ -89,8 +91,6 @@ impl HighlightTag { HighlightTag::Union => "union", HighlightTag::Local => "variable", HighlightTag::UnresolvedReference => "unresolved_reference", - HighlightTag::FormatSpecifier => "format_specifier", - HighlightTag::Operator => "operator", } } } diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 7dc229cab..36a1aa419 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -258,3 +258,34 @@ fn main() { fs::write(dst_file, &actual_html).unwrap(); assert_eq_text!(expected_html, actual_html); } + +#[test] +fn test_unsafe_highlighting() { + let (analysis, file_id) = single_file( + r#" +unsafe fn unsafe_fn() {} + +struct HasUnsafeFn; + +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; + } +} +"# + .trim(), + ); + let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_unsafe.html"); + let actual_html = &analysis.highlight_as_html(file_id, false).unwrap(); + let expected_html = &read_text(&dst_file); + fs::write(dst_file, &actual_html).unwrap(); + assert_eq_text!(expected_html, actual_html); +} -- cgit v1.2.3