X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fide%2Fsrc%2Fsyntax_highlighting.rs;h=7d92c5051b14ff77fa4bb42b547a2b9e285bccaf;hb=1bbef5af85f47a1c8a4dc0d98c8c76bdeb1359af;hp=f20d629fbf1d069867ead0036be92c953bb3fd26;hpb=8e9ccbf97a70259b6c6576e8fd7d77d28238737e;p=rust.git diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index f20d629fbf1..7d92c5051b1 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -16,7 +16,7 @@ use ide_db::RootDatabase; use rustc_hash::FxHashMap; use syntax::{ - ast::{self, HasFormatSpecifier}, + ast::{self, IsString}, AstNode, AstToken, NodeOrToken, SyntaxKind::*, SyntaxNode, TextRange, WalkEvent, T, @@ -237,6 +237,20 @@ fn traverse( continue; } Some(item) if sema.is_attr_macro_call(&item) => current_attr_call = Some(item), + Some(item) if current_attr_call.is_none() => { + let adt = match item { + ast::Item::Enum(it) => Some(ast::Adt::Enum(it)), + ast::Item::Struct(it) => Some(ast::Adt::Struct(it)), + ast::Item::Union(it) => Some(ast::Adt::Union(it)), + _ => None, + }; + match adt { + Some(adt) if sema.is_derive_annotated(&adt) => { + current_attr_call = Some(adt.into()); + } + _ => (), + } + } None if ast::Attr::can_cast(node.kind()) => inside_attribute = true, _ => (), }, @@ -336,17 +350,19 @@ fn traverse( } highlight_format_string(hl, &string, &expanded_string, range); // Highlight escape sequences - if let Some(char_ranges) = string.char_ranges() { - for (piece_range, _) in char_ranges.iter().filter(|(_, char)| char.is_ok()) { - if string.text()[piece_range.start().into()..].starts_with('\\') { - hl.add(HlRange { - range: piece_range + range.start(), - highlight: HlTag::EscapeSequence.into(), - binding_hash: None, - }); - } + string.escaped_char_ranges(&mut |piece_range, char| { + if char.is_err() { + return; } - } + + if string.text()[piece_range.start().into()..].starts_with('\\') { + hl.add(HlRange { + range: piece_range + range.start(), + highlight: HlTag::EscapeSequence.into(), + binding_hash: None, + }); + } + }); } } @@ -359,7 +375,7 @@ fn traverse( syntactic_name_ref_highlighting, node, ), - NodeOrToken::Token(token) => highlight::token(sema, krate, token).zip(Some(None)), + NodeOrToken::Token(token) => highlight::token(sema, token).zip(Some(None)), }; if let Some((mut highlight, binding_hash)) = element { if inside_attribute {