Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/syntax_highlighting.rs')
-rw-r--r--crates/ide/src/syntax_highlighting.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 45582f54b4..366a3c969f 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -393,13 +393,25 @@ fn traverse(
// Attempt to descend tokens into macro-calls.
let res = match element {
NodeOrToken::Token(token) if token.kind() != COMMENT => {
- let token = sema.descend_into_macros_single(
- match attr_or_derive_item {
- Some(AttrOrDerive::Attr(_)) => DescendPreference::SameKind,
- Some(AttrOrDerive::Derive(_)) | None => DescendPreference::None,
- },
- token,
- );
+ let token = if token.kind() == STRING {
+ // for strings, try to prefer a string that has not been lost in a token
+ // tree
+ // FIXME: This should be done for everything, but check perf first
+ sema.descend_into_macros(DescendPreference::SameKind, token)
+ .into_iter()
+ .max_by_key(|it| {
+ it.parent().map_or(false, |it| it.kind() != TOKEN_TREE)
+ })
+ .unwrap()
+ } else {
+ sema.descend_into_macros_single(
+ match attr_or_derive_item {
+ Some(AttrOrDerive::Attr(_)) => DescendPreference::SameKind,
+ Some(AttrOrDerive::Derive(_)) | None => DescendPreference::None,
+ },
+ token,
+ )
+ };
match token.parent().and_then(ast::NameLike::cast) {
// Remap the token into the wrapping single token nodes
Some(parent) => match (token.kind(), parent.syntax().kind()) {