From f5a81ec4683613bd62624811733345d627f2127b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 30 Jan 2021 18:19:21 +0300 Subject: Upgrade rowan Notably, new rowan comes with support for mutable syntax trees. --- crates/ide/src/syntax_highlighting.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'crates/ide/src/syntax_highlighting.rs') 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( Some(range) => { let node = match source_file.syntax().covering_element(range) { NodeOrToken::Node(it) => it, - NodeOrToken::Token(it) => it.parent(), + NodeOrToken::Token(it) => it.parent().unwrap(), }; (node, range) } @@ -167,16 +167,19 @@ fn traverse( let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT { // Inside a macro -- expand it first let token = match element.clone().into_token() { - Some(it) if it.parent().kind() == TOKEN_TREE => it, + Some(it) if it.parent().map_or(false, |it| it.kind() == TOKEN_TREE) => it, _ => continue, }; let token = sema.descend_into_macros(token.clone()); - let parent = token.parent(); - - // We only care Name and Name_ref - match (token.kind(), parent.kind()) { - (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(), - _ => token.into(), + match token.parent() { + Some(parent) => { + // We only care Name and Name_ref + match (token.kind(), parent.kind()) { + (IDENT, NAME) | (IDENT, NAME_REF) => parent.into(), + _ => token.into(), + } + } + None => token.into(), } } else { element.clone() -- cgit v1.2.3