Skip to content

Commit 8bf2d4f

Browse files
bors[bot]Veykril
andauthored
Merge #10404
10404: minor: Simplify r=Veykril a=Veykril Fixes #10405 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 4f3ce62 + 0c7ea0c commit 8bf2d4f

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn traverse(
197197
let mut bindings_shadow_count: FxHashMap<Name, u32> = FxHashMap::default();
198198

199199
let mut current_macro_call: Option<ast::MacroCall> = None;
200-
let mut current_attr_macro_call = None;
200+
let mut current_attr_call = None;
201201
let mut current_macro: Option<ast::Macro> = None;
202202
let mut macro_highlighter = MacroHighlighter::default();
203203
let mut inside_attribute = false;
@@ -236,7 +236,7 @@ fn traverse(
236236
},
237237
ast::Item(item) => {
238238
if sema.is_attr_macro_call(&item) {
239-
current_attr_macro_call = Some(item);
239+
current_attr_call = Some(item);
240240
}
241241
},
242242
ast::Attr(__) => inside_attribute = true,
@@ -257,8 +257,8 @@ fn traverse(
257257
macro_highlighter = MacroHighlighter::default();
258258
},
259259
ast::Item(item) => {
260-
if current_attr_macro_call == Some(item) {
261-
current_attr_macro_call = None;
260+
if current_attr_call == Some(item) {
261+
current_attr_call = None;
262262
}
263263
},
264264
ast::Attr(__) => inside_attribute = false,
@@ -287,34 +287,28 @@ fn traverse(
287287
}
288288
}
289289

290-
let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT {
290+
let descend_token = (current_macro_call.is_some() || current_attr_call.is_some())
291+
&& element.kind() != COMMENT;
292+
let element_to_highlight = if descend_token {
291293
// Inside a macro -- expand it first
292294
let token = match element.clone().into_token() {
293-
Some(it) if it.parent().map_or(false, |it| it.kind() == TOKEN_TREE) => it,
294-
_ => continue,
295-
};
296-
let token = sema.descend_into_macros(token.clone());
297-
match token.parent() {
298-
Some(parent) => {
299-
// We only care Name and Name_ref
300-
match (token.kind(), parent.kind()) {
301-
(IDENT, NAME | NAME_REF) => parent.into(),
302-
_ => token.into(),
295+
Some(it) if current_macro_call.is_some() => {
296+
let not_in_tt = it.parent().map_or(true, |it| it.kind() != TOKEN_TREE);
297+
if not_in_tt {
298+
continue;
303299
}
300+
it
304301
}
305-
None => token.into(),
306-
}
307-
} else if current_attr_macro_call.is_some() {
308-
let token = match element.clone().into_token() {
309302
Some(it) => it,
310303
_ => continue,
311304
};
312-
let token = sema.descend_into_macros(token.clone());
305+
let token = sema.descend_into_macros(token);
313306
match token.parent() {
314307
Some(parent) => {
315308
// We only care Name and Name_ref
316309
match (token.kind(), parent.kind()) {
317-
(IDENT, NAME | NAME_REF) => parent.into(),
310+
(T![ident], NAME | NAME_REF) => parent.into(),
311+
(T![self] | T![super] | T![crate], NAME_REF) => parent.into(),
318312
_ => token.into(),
319313
}
320314
}
@@ -324,11 +318,12 @@ fn traverse(
324318
element.clone()
325319
};
326320

327-
if let Some(token) = element.as_token().cloned().and_then(ast::String::cast) {
321+
if let Some(token) = element.into_token().and_then(ast::String::cast) {
328322
if token.is_raw() {
329-
let expanded = element_to_highlight.as_token().unwrap().clone();
330-
if inject::ra_fixture(hl, sema, token, expanded).is_some() {
331-
continue;
323+
if let Some(expanded) = element_to_highlight.as_token() {
324+
if inject::ra_fixture(hl, sema, token, expanded.clone()).is_some() {
325+
continue;
326+
}
332327
}
333328
}
334329
}
@@ -351,7 +346,7 @@ fn traverse(
351346
hl.add(HlRange { range, highlight, binding_hash });
352347
}
353348

354-
if let Some(string) = element_to_highlight.as_token().cloned().and_then(ast::String::cast) {
349+
if let Some(string) = element_to_highlight.into_token().and_then(ast::String::cast) {
355350
highlight_format_string(hl, &string, range);
356351
// Highlight escape sequences
357352
if let Some(char_ranges) = string.char_ranges() {
@@ -376,9 +371,8 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
376371
let range_start = name_ref.syntax().text_range().start();
377372
let mut range_end = name_ref.syntax().text_range().end();
378373
for sibling in path.syntax().siblings_with_tokens(Direction::Next) {
379-
match sibling.kind() {
380-
T![!] | IDENT => range_end = sibling.text_range().end(),
381-
_ => (),
374+
if let T![!] | T![ident] = sibling.kind() {
375+
range_end = sibling.text_range().end();
382376
}
383377
}
384378

crates/rust-analyzer/src/semantic_tokens.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! define_semantic_token_modifiers {
8181
SemanticTokenModifier::ABSTRACT,
8282
SemanticTokenModifier::DEPRECATED,
8383
SemanticTokenModifier::READONLY,
84+
SemanticTokenModifier::DEFAULT_LIBRARY,
8485
$($ident),*
8586
];
8687
};

0 commit comments

Comments
 (0)