diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 9bed329d8..870146d24 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs | |||
@@ -64,7 +64,7 @@ pub(crate) fn highlight( | |||
64 | Some(range) => { | 64 | Some(range) => { |
65 | let node = match source_file.syntax().covering_element(range) { | 65 | let node = match source_file.syntax().covering_element(range) { |
66 | NodeOrToken::Node(it) => it, | 66 | NodeOrToken::Node(it) => it, |
67 | NodeOrToken::Token(it) => it.parent(), | 67 | NodeOrToken::Token(it) => it.parent().unwrap(), |
68 | }; | 68 | }; |
69 | (node, range) | 69 | (node, range) |
70 | } | 70 | } |
@@ -167,16 +167,19 @@ fn traverse( | |||
167 | let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT { | 167 | let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT { |
168 | // Inside a macro -- expand it first | 168 | // Inside a macro -- expand it first |
169 | let token = match element.clone().into_token() { | 169 | let token = match element.clone().into_token() { |
170 | Some(it) if it.parent().kind() == TOKEN_TREE => it, | 170 | Some(it) if it.parent().map_or(false, |it| it.kind() == TOKEN_TREE) => it, |
171 | _ => continue, | 171 | _ => continue, |
172 | }; | 172 | }; |
173 | let token = sema.descend_into_macros(token.clone()); | 173 | let token = sema.descend_into_macros(token.clone()); |
174 | let parent = token.parent(); | 174 | match token.parent() { |
175 | 175 | Some(parent) => { | |
176 | // We only care Name and Name_ref | 176 | // We only care Name and Name_ref |
177 | match (token.kind(), parent.kind()) { | 177 | match (token.kind(), parent.kind()) { |
178 | (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(), | 178 | (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(), |
179 | _ => token.into(), | 179 | _ => token.into(), |
180 | } | ||
181 | } | ||
182 | None => token.into(), | ||
180 | } | 183 | } |
181 | } else { | 184 | } else { |
182 | element.clone() | 185 | element.clone() |