diff options
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 15e75709c..0228ee7e9 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -17,31 +17,31 @@ use crate::{ | |||
17 | }; | 17 | }; |
18 | 18 | ||
19 | pub mod tags { | 19 | pub mod tags { |
20 | pub(crate) const FIELD: &'static str = "field"; | 20 | pub(crate) const FIELD: &str = "field"; |
21 | pub(crate) const FUNCTION: &'static str = "function"; | 21 | pub(crate) const FUNCTION: &str = "function"; |
22 | pub(crate) const MODULE: &'static str = "module"; | 22 | pub(crate) const MODULE: &str = "module"; |
23 | pub(crate) const TYPE: &'static str = "type"; | 23 | pub(crate) const TYPE: &str = "type"; |
24 | pub(crate) const CONSTANT: &'static str = "constant"; | 24 | pub(crate) const CONSTANT: &str = "constant"; |
25 | pub(crate) const MACRO: &'static str = "macro"; | 25 | pub(crate) const MACRO: &str = "macro"; |
26 | pub(crate) const VARIABLE: &'static str = "variable"; | 26 | pub(crate) const VARIABLE: &str = "variable"; |
27 | pub(crate) const VARIABLE_MUT: &'static str = "variable.mut"; | 27 | pub(crate) const VARIABLE_MUT: &str = "variable.mut"; |
28 | pub(crate) const TEXT: &'static str = "text"; | 28 | pub(crate) const TEXT: &str = "text"; |
29 | 29 | ||
30 | pub(crate) const TYPE_BUILTIN: &'static str = "type.builtin"; | 30 | pub(crate) const TYPE_BUILTIN: &str = "type.builtin"; |
31 | pub(crate) const TYPE_SELF: &'static str = "type.self"; | 31 | pub(crate) const TYPE_SELF: &str = "type.self"; |
32 | pub(crate) const TYPE_PARAM: &'static str = "type.param"; | 32 | pub(crate) const TYPE_PARAM: &str = "type.param"; |
33 | pub(crate) const TYPE_LIFETIME: &'static str = "type.lifetime"; | 33 | pub(crate) const TYPE_LIFETIME: &str = "type.lifetime"; |
34 | 34 | ||
35 | pub(crate) const LITERAL_BYTE: &'static str = "literal.byte"; | 35 | pub(crate) const LITERAL_BYTE: &str = "literal.byte"; |
36 | pub(crate) const LITERAL_NUMERIC: &'static str = "literal.numeric"; | 36 | pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric"; |
37 | pub(crate) const LITERAL_CHAR: &'static str = "literal.char"; | 37 | pub(crate) const LITERAL_CHAR: &str = "literal.char"; |
38 | pub(crate) const LITERAL_COMMENT: &'static str = "comment"; | 38 | pub(crate) const LITERAL_COMMENT: &str = "comment"; |
39 | pub(crate) const LITERAL_STRING: &'static str = "string"; | 39 | pub(crate) const LITERAL_STRING: &str = "string"; |
40 | pub(crate) const LITERAL_ATTRIBUTE: &'static str = "attribute"; | 40 | pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute"; |
41 | 41 | ||
42 | pub(crate) const KEYWORD_UNSAFE: &'static str = "keyword.unsafe"; | 42 | pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe"; |
43 | pub(crate) const KEYWORD_CONTROL: &'static str = "keyword.control"; | 43 | pub(crate) const KEYWORD_CONTROL: &str = "keyword.control"; |
44 | pub(crate) const KEYWORD: &'static str = "keyword"; | 44 | pub(crate) const KEYWORD: &str = "keyword"; |
45 | } | 45 | } |
46 | 46 | ||
47 | #[derive(Debug)] | 47 | #[derive(Debug)] |
@@ -102,11 +102,10 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
102 | COMMENT => tags::LITERAL_COMMENT, | 102 | COMMENT => tags::LITERAL_COMMENT, |
103 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => tags::LITERAL_STRING, | 103 | STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => tags::LITERAL_STRING, |
104 | ATTR => tags::LITERAL_ATTRIBUTE, | 104 | ATTR => tags::LITERAL_ATTRIBUTE, |
105 | // Special-case field init shorthand | ||
106 | NAME_REF if node.parent().and_then(ast::RecordField::cast).is_some() => tags::FIELD, | ||
107 | NAME_REF if node.ancestors().any(|it| it.kind() == ATTR) => continue, | ||
105 | NAME_REF => { | 108 | NAME_REF => { |
106 | if node.ancestors().any(|it| it.kind() == ATTR) { | ||
107 | continue; | ||
108 | } | ||
109 | |||
110 | let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); | 109 | let name_ref = node.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); |
111 | let name_kind = | 110 | let name_kind = |
112 | classify_name_ref(db, InFile::new(file_id.into(), &name_ref)).map(|d| d.kind); | 111 | classify_name_ref(db, InFile::new(file_id.into(), &name_ref)).map(|d| d.kind); |
@@ -259,9 +258,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | |||
259 | SelfType(_) => tags::TYPE_SELF, | 258 | SelfType(_) => tags::TYPE_SELF, |
260 | TypeParam(_) => tags::TYPE_PARAM, | 259 | TypeParam(_) => tags::TYPE_PARAM, |
261 | Local(local) => { | 260 | Local(local) => { |
262 | if local.is_mut(db) { | 261 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { |
263 | tags::VARIABLE_MUT | ||
264 | } else if local.ty(db).is_mutable_reference() { | ||
265 | tags::VARIABLE_MUT | 262 | tags::VARIABLE_MUT |
266 | } else { | 263 | } else { |
267 | tags::VARIABLE | 264 | tags::VARIABLE |
@@ -282,6 +279,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
282 | 279 | ||
283 | .comment { color: #7F9F7F; } | 280 | .comment { color: #7F9F7F; } |
284 | .string { color: #CC9393; } | 281 | .string { color: #CC9393; } |
282 | .field { color: #94BFF3; } | ||
285 | .function { color: #93E0E3; } | 283 | .function { color: #93E0E3; } |
286 | .parameter { color: #94BFF3; } | 284 | .parameter { color: #94BFF3; } |
287 | .text { color: #DCDCCC; } | 285 | .text { color: #DCDCCC; } |
@@ -327,7 +325,8 @@ fn main() { | |||
327 | 325 | ||
328 | let mut vec = Vec::new(); | 326 | let mut vec = Vec::new(); |
329 | if true { | 327 | if true { |
330 | vec.push(Foo { x: 0, y: 1 }); | 328 | let x = 92; |
329 | vec.push(Foo { x, y: 1 }); | ||
331 | } | 330 | } |
332 | unsafe { vec.set_len(0); } | 331 | unsafe { vec.set_len(0); } |
333 | 332 | ||