diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/html.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tags.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting/tests.rs | 53 |
3 files changed, 67 insertions, 4 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index ff0eeeb52..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 | |||
69 | .string_literal { color: #CC9393; } | 69 | .string_literal { color: #CC9393; } |
70 | .field { color: #94BFF3; } | 70 | .field { color: #94BFF3; } |
71 | .function { color: #93E0E3; } | 71 | .function { color: #93E0E3; } |
72 | .operator.unsafe { color: #E28C14; } | ||
72 | .parameter { color: #94BFF3; } | 73 | .parameter { color: #94BFF3; } |
73 | .text { color: #DCDCCC; } | 74 | .text { color: #DCDCCC; } |
74 | .type { color: #7CB8BB; } | 75 | .type { color: #7CB8BB; } |
@@ -76,6 +77,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
76 | .type_param { color: #DFAF8F; } | 77 | .type_param { color: #DFAF8F; } |
77 | .attribute { color: #94BFF3; } | 78 | .attribute { color: #94BFF3; } |
78 | .numeric_literal { color: #BFEBBF; } | 79 | .numeric_literal { color: #BFEBBF; } |
80 | .bool_literal { color: #BFE6EB; } | ||
79 | .macro { color: #94BFF3; } | 81 | .macro { color: #94BFF3; } |
80 | .module { color: #AFD8AF; } | 82 | .module { color: #AFD8AF; } |
81 | .variable { color: #DCDCCC; } | 83 | .variable { color: #DCDCCC; } |
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index be1a0f12b..94f466966 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); | |||
15 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 15 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
16 | pub enum HighlightTag { | 16 | pub enum HighlightTag { |
17 | Attribute, | 17 | Attribute, |
18 | BoolLiteral, | ||
18 | BuiltinType, | 19 | BuiltinType, |
19 | ByteLiteral, | 20 | ByteLiteral, |
20 | CharLiteral, | 21 | CharLiteral, |
@@ -23,12 +24,15 @@ pub enum HighlightTag { | |||
23 | Enum, | 24 | Enum, |
24 | EnumVariant, | 25 | EnumVariant, |
25 | Field, | 26 | Field, |
27 | FormatSpecifier, | ||
26 | Function, | 28 | Function, |
27 | Keyword, | 29 | Keyword, |
28 | Lifetime, | 30 | Lifetime, |
29 | Macro, | 31 | Macro, |
30 | Module, | 32 | Module, |
31 | NumericLiteral, | 33 | NumericLiteral, |
34 | Operator, | ||
35 | SelfKeyword, | ||
32 | SelfType, | 36 | SelfType, |
33 | Static, | 37 | Static, |
34 | StringLiteral, | 38 | StringLiteral, |
@@ -39,14 +43,15 @@ pub enum HighlightTag { | |||
39 | Union, | 43 | Union, |
40 | Local, | 44 | Local, |
41 | UnresolvedReference, | 45 | UnresolvedReference, |
42 | FormatSpecifier, | ||
43 | } | 46 | } |
44 | 47 | ||
45 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 48 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
46 | #[repr(u8)] | 49 | #[repr(u8)] |
47 | pub enum HighlightModifier { | 50 | pub enum HighlightModifier { |
51 | /// Used to differentiate individual elements within attributes. | ||
52 | Attribute = 0, | ||
48 | /// Used with keywords like `if` and `break`. | 53 | /// Used with keywords like `if` and `break`. |
49 | ControlFlow = 0, | 54 | ControlFlow, |
50 | /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is | 55 | /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is |
51 | /// not. | 56 | /// not. |
52 | Definition, | 57 | Definition, |
@@ -58,6 +63,7 @@ impl HighlightTag { | |||
58 | fn as_str(self) -> &'static str { | 63 | fn as_str(self) -> &'static str { |
59 | match self { | 64 | match self { |
60 | HighlightTag::Attribute => "attribute", | 65 | HighlightTag::Attribute => "attribute", |
66 | HighlightTag::BoolLiteral => "bool_literal", | ||
61 | HighlightTag::BuiltinType => "builtin_type", | 67 | HighlightTag::BuiltinType => "builtin_type", |
62 | HighlightTag::ByteLiteral => "byte_literal", | 68 | HighlightTag::ByteLiteral => "byte_literal", |
63 | HighlightTag::CharLiteral => "char_literal", | 69 | HighlightTag::CharLiteral => "char_literal", |
@@ -66,12 +72,15 @@ impl HighlightTag { | |||
66 | HighlightTag::Enum => "enum", | 72 | HighlightTag::Enum => "enum", |
67 | HighlightTag::EnumVariant => "enum_variant", | 73 | HighlightTag::EnumVariant => "enum_variant", |
68 | HighlightTag::Field => "field", | 74 | HighlightTag::Field => "field", |
75 | HighlightTag::FormatSpecifier => "format_specifier", | ||
69 | HighlightTag::Function => "function", | 76 | HighlightTag::Function => "function", |
70 | HighlightTag::Keyword => "keyword", | 77 | HighlightTag::Keyword => "keyword", |
71 | HighlightTag::Lifetime => "lifetime", | 78 | HighlightTag::Lifetime => "lifetime", |
72 | HighlightTag::Macro => "macro", | 79 | HighlightTag::Macro => "macro", |
73 | HighlightTag::Module => "module", | 80 | HighlightTag::Module => "module", |
74 | HighlightTag::NumericLiteral => "numeric_literal", | 81 | HighlightTag::NumericLiteral => "numeric_literal", |
82 | HighlightTag::Operator => "operator", | ||
83 | HighlightTag::SelfKeyword => "self_keyword", | ||
75 | HighlightTag::SelfType => "self_type", | 84 | HighlightTag::SelfType => "self_type", |
76 | HighlightTag::Static => "static", | 85 | HighlightTag::Static => "static", |
77 | HighlightTag::StringLiteral => "string_literal", | 86 | HighlightTag::StringLiteral => "string_literal", |
@@ -82,7 +91,6 @@ impl HighlightTag { | |||
82 | HighlightTag::Union => "union", | 91 | HighlightTag::Union => "union", |
83 | HighlightTag::Local => "variable", | 92 | HighlightTag::Local => "variable", |
84 | HighlightTag::UnresolvedReference => "unresolved_reference", | 93 | HighlightTag::UnresolvedReference => "unresolved_reference", |
85 | HighlightTag::FormatSpecifier => "format_specifier", | ||
86 | } | 94 | } |
87 | } | 95 | } |
88 | } | 96 | } |
@@ -95,6 +103,7 @@ impl fmt::Display for HighlightTag { | |||
95 | 103 | ||
96 | impl HighlightModifier { | 104 | impl HighlightModifier { |
97 | const ALL: &'static [HighlightModifier] = &[ | 105 | const ALL: &'static [HighlightModifier] = &[ |
106 | HighlightModifier::Attribute, | ||
98 | HighlightModifier::ControlFlow, | 107 | HighlightModifier::ControlFlow, |
99 | HighlightModifier::Definition, | 108 | HighlightModifier::Definition, |
100 | HighlightModifier::Mutable, | 109 | HighlightModifier::Mutable, |
@@ -103,6 +112,7 @@ impl HighlightModifier { | |||
103 | 112 | ||
104 | fn as_str(self) -> &'static str { | 113 | fn as_str(self) -> &'static str { |
105 | match self { | 114 | match self { |
115 | HighlightModifier::Attribute => "attribute", | ||
106 | HighlightModifier::ControlFlow => "control", | 116 | HighlightModifier::ControlFlow => "control", |
107 | HighlightModifier::Definition => "declaration", | 117 | HighlightModifier::Definition => "declaration", |
108 | HighlightModifier::Mutable => "mutable", | 118 | HighlightModifier::Mutable => "mutable", |
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index d2926ba78..36a1aa419 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs | |||
@@ -17,6 +17,18 @@ struct Foo { | |||
17 | pub y: i32, | 17 | pub y: i32, |
18 | } | 18 | } |
19 | 19 | ||
20 | trait Bar { | ||
21 | fn bar(&self) -> i32; | ||
22 | } | ||
23 | |||
24 | impl Bar for Foo { | ||
25 | fn bar(&self) -> i32 { | ||
26 | self.x | ||
27 | } | ||
28 | } | ||
29 | |||
30 | static mut STATIC_MUT: i32 = 0; | ||
31 | |||
20 | fn foo<'a, T>() -> T { | 32 | fn foo<'a, T>() -> T { |
21 | foo::<'a, i32>() | 33 | foo::<'a, i32>() |
22 | } | 34 | } |
@@ -40,7 +52,14 @@ fn main() { | |||
40 | let x = 92; | 52 | let x = 92; |
41 | vec.push(Foo { x, y: 1 }); | 53 | vec.push(Foo { x, y: 1 }); |
42 | } | 54 | } |
43 | unsafe { vec.set_len(0); } | 55 | unsafe { |
56 | vec.set_len(0); | ||
57 | STATIC_MUT = 1; | ||
58 | } | ||
59 | |||
60 | for e in vec { | ||
61 | // Do nothing | ||
62 | } | ||
44 | 63 | ||
45 | let mut x = 42; | 64 | let mut x = 42; |
46 | let y = &mut x; | 65 | let y = &mut x; |
@@ -199,6 +218,7 @@ fn main() { | |||
199 | println!("{argument}", argument = "test"); // => "test" | 218 | println!("{argument}", argument = "test"); // => "test" |
200 | println!("{name} {}", 1, name = 2); // => "2 1" | 219 | println!("{name} {}", 1, name = 2); // => "2 1" |
201 | println!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" | 220 | println!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b" |
221 | println!("{{{}}}", 2); // => "{2}" | ||
202 | println!("Hello {:5}!", "x"); | 222 | println!("Hello {:5}!", "x"); |
203 | println!("Hello {:1$}!", "x", 5); | 223 | println!("Hello {:1$}!", "x", 5); |
204 | println!("Hello {1:0$}!", 5, "x"); | 224 | println!("Hello {1:0$}!", 5, "x"); |
@@ -238,3 +258,34 @@ fn main() { | |||
238 | fs::write(dst_file, &actual_html).unwrap(); | 258 | fs::write(dst_file, &actual_html).unwrap(); |
239 | assert_eq_text!(expected_html, actual_html); | 259 | assert_eq_text!(expected_html, actual_html); |
240 | } | 260 | } |
261 | |||
262 | #[test] | ||
263 | fn test_unsafe_highlighting() { | ||
264 | let (analysis, file_id) = single_file( | ||
265 | r#" | ||
266 | unsafe fn unsafe_fn() {} | ||
267 | |||
268 | struct HasUnsafeFn; | ||
269 | |||
270 | impl HasUnsafeFn { | ||
271 | unsafe fn unsafe_method(&self) {} | ||
272 | } | ||
273 | |||
274 | fn main() { | ||
275 | let x = &5 as *const usize; | ||
276 | unsafe { | ||
277 | unsafe_fn(); | ||
278 | HasUnsafeFn.unsafe_method(); | ||
279 | let y = *x; | ||
280 | let z = -x; | ||
281 | } | ||
282 | } | ||
283 | "# | ||
284 | .trim(), | ||
285 | ); | ||
286 | let dst_file = project_dir().join("crates/ra_ide/src/snapshots/highlight_unsafe.html"); | ||
287 | let actual_html = &analysis.highlight_as_html(file_id, false).unwrap(); | ||
288 | let expected_html = &read_text(&dst_file); | ||
289 | fs::write(dst_file, &actual_html).unwrap(); | ||
290 | assert_eq_text!(expected_html, actual_html); | ||
291 | } | ||