Unnamed repository; edit this file 'description' to name the repository.
Merge #10404
10404: minor: Simplify r=Veykril a=Veykril Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10405 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
bors[bot] 2021-10-01
parent 4f3ce62 · parent 0c7ea0c · commit 8bf2d4f
-rw-r--r--crates/ide/src/syntax_highlighting.rs52
-rw-r--r--crates/rust-analyzer/src/semantic_tokens.rs1
2 files changed, 24 insertions, 29 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 6d352942ca..b4331fc09f 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -197,7 +197,7 @@ fn traverse(
let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
let mut current_macro_call: Option<ast::MacroCall> = None;
- let mut current_attr_macro_call = None;
+ let mut current_attr_call = None;
let mut current_macro: Option<ast::Macro> = None;
let mut macro_highlighter = MacroHighlighter::default();
let mut inside_attribute = false;
@@ -236,7 +236,7 @@ fn traverse(
},
ast::Item(item) => {
if sema.is_attr_macro_call(&item) {
- current_attr_macro_call = Some(item);
+ current_attr_call = Some(item);
}
},
ast::Attr(__) => inside_attribute = true,
@@ -257,8 +257,8 @@ fn traverse(
macro_highlighter = MacroHighlighter::default();
},
ast::Item(item) => {
- if current_attr_macro_call == Some(item) {
- current_attr_macro_call = None;
+ if current_attr_call == Some(item) {
+ current_attr_call = None;
}
},
ast::Attr(__) => inside_attribute = false,
@@ -287,34 +287,28 @@ fn traverse(
}
}
- let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT {
+ let descend_token = (current_macro_call.is_some() || current_attr_call.is_some())
+ && element.kind() != COMMENT;
+ let element_to_highlight = if descend_token {
// Inside a macro -- expand it first
let token = match element.clone().into_token() {
- Some(it) if it.parent().map_or(false, |it| it.kind() == TOKEN_TREE) => it,
- _ => continue,
- };
- let token = sema.descend_into_macros(token.clone());
- match token.parent() {
- Some(parent) => {
- // We only care Name and Name_ref
- match (token.kind(), parent.kind()) {
- (IDENT, NAME | NAME_REF) => parent.into(),
- _ => token.into(),
+ Some(it) if current_macro_call.is_some() => {
+ let not_in_tt = it.parent().map_or(true, |it| it.kind() != TOKEN_TREE);
+ if not_in_tt {
+ continue;
}
+ it
}
- None => token.into(),
- }
- } else if current_attr_macro_call.is_some() {
- let token = match element.clone().into_token() {
Some(it) => it,
_ => continue,
};
- let token = sema.descend_into_macros(token.clone());
+ let token = sema.descend_into_macros(token);
match token.parent() {
Some(parent) => {
// We only care Name and Name_ref
match (token.kind(), parent.kind()) {
- (IDENT, NAME | NAME_REF) => parent.into(),
+ (T![ident], NAME | NAME_REF) => parent.into(),
+ (T![self] | T![super] | T![crate], NAME_REF) => parent.into(),
_ => token.into(),
}
}
@@ -324,11 +318,12 @@ fn traverse(
element.clone()
};
- if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
+ if let Some(token) = element.into_token().and_then(ast::String::cast) {
if token.is_raw() {
- let expanded = element_to_highlight.as_token().unwrap().clone();
- if inject::ra_fixture(hl, sema, token, expanded).is_some() {
- continue;
+ if let Some(expanded) = element_to_highlight.as_token() {
+ if inject::ra_fixture(hl, sema, token, expanded.clone()).is_some() {
+ continue;
+ }
}
}
}
@@ -351,7 +346,7 @@ fn traverse(
hl.add(HlRange { range, highlight, binding_hash });
}
- if let Some(string) = element_to_highlight.as_token().cloned().and_then(ast::String::cast) {
+ if let Some(string) = element_to_highlight.into_token().and_then(ast::String::cast) {
highlight_format_string(hl, &string, range);
// Highlight escape sequences
if let Some(char_ranges) = string.char_ranges() {
@@ -376,9 +371,8 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
let range_start = name_ref.syntax().text_range().start();
let mut range_end = name_ref.syntax().text_range().end();
for sibling in path.syntax().siblings_with_tokens(Direction::Next) {
- match sibling.kind() {
- T![!] | IDENT => range_end = sibling.text_range().end(),
- _ => (),
+ if let T![!] | T![ident] = sibling.kind() {
+ range_end = sibling.text_range().end();
}
}
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index 8a5d09ad78..d5f579f11d 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -81,6 +81,7 @@ macro_rules! define_semantic_token_modifiers {
SemanticTokenModifier::ABSTRACT,
SemanticTokenModifier::DEPRECATED,
SemanticTokenModifier::READONLY,
+ SemanticTokenModifier::DEFAULT_LIBRARY,
$($ident),*
];
};