mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Apply suggestions from code review
Co-Authored-By: bjorn3 <bjorn3@users.noreply.github.com>
This commit is contained in:
parent
ac798e1f7c
commit
b2829a5216
2 changed files with 32 additions and 34 deletions
|
@ -194,7 +194,7 @@ pub(crate) fn highlight(
|
|||
let token = sema.descend_into_macros(token.clone());
|
||||
let parent = token.parent();
|
||||
|
||||
// Check if macro takes a format string and remeber it for highlighting later.
|
||||
// Check if macro takes a format string and remember it for highlighting later.
|
||||
// The macros that accept a format string expand to a compiler builtin macros
|
||||
// `format_args` and `format_args_nl`.
|
||||
if let Some(fmt_macro_call) = parent.parent().and_then(ast::MacroCall::cast) {
|
||||
|
@ -233,8 +233,7 @@ pub(crate) fn highlight(
|
|||
}
|
||||
}
|
||||
|
||||
let is_format_string =
|
||||
format_string.as_ref().map(|fs| fs == &element_to_highlight).unwrap_or_default();
|
||||
let is_format_string = format_string.as_ref() == Some(&element_to_highlight);
|
||||
|
||||
if let Some((highlight, binding_hash)) =
|
||||
highlight_element(&sema, &mut bindings_shadow_count, element_to_highlight.clone())
|
||||
|
@ -245,7 +244,7 @@ pub(crate) fn highlight(
|
|||
{
|
||||
stack.push();
|
||||
if is_format_string {
|
||||
string.lex_format_specifier(&mut |piece_range, kind| {
|
||||
string.lex_format_specifier(|piece_range, kind| {
|
||||
let highlight = match kind {
|
||||
FormatSpecifier::Open
|
||||
| FormatSpecifier::Close
|
||||
|
|
|
@ -192,7 +192,7 @@ pub enum FormatSpecifier {
|
|||
}
|
||||
|
||||
pub trait HasFormatSpecifier: AstToken {
|
||||
fn lex_format_specifier<F>(&self, callback: &mut F)
|
||||
fn lex_format_specifier<F>(&self, mut callback: F)
|
||||
where
|
||||
F: FnMut(TextRange, FormatSpecifier),
|
||||
{
|
||||
|
@ -217,21 +217,15 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
FormatSpecifier::Open,
|
||||
);
|
||||
|
||||
let next_char = if let Some(c) = chars.clone().next() {
|
||||
c
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
|
||||
// check for integer/identifier
|
||||
match next_char {
|
||||
match chars.clone().next().unwrap_or_default() {
|
||||
'0'..='9' => {
|
||||
// integer
|
||||
read_integer(&mut chars, initial_len, callback);
|
||||
read_integer(&mut chars, initial_len, &mut callback);
|
||||
}
|
||||
'a'..='z' | 'A'..='Z' | '_' => {
|
||||
// identifier
|
||||
read_identifier(&mut chars, initial_len, callback);
|
||||
read_identifier(&mut chars, initial_len, &mut callback);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -241,7 +235,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Colon,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
|
||||
// check for fill/align
|
||||
|
@ -255,13 +249,13 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Fill,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
skip_char_and_emit(
|
||||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Align,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => match first {
|
||||
|
@ -270,7 +264,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Align,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -284,7 +278,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Sign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -296,7 +290,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::NumberSign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -310,25 +304,25 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Zero,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
|
||||
// width
|
||||
match chars.clone().next().unwrap_or_default() {
|
||||
'0'..='9' => {
|
||||
read_integer(&mut chars, initial_len, callback);
|
||||
read_integer(&mut chars, initial_len, &mut callback);
|
||||
if chars.clone().next() == Some('$') {
|
||||
skip_char_and_emit(
|
||||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::DollarSign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
}
|
||||
'a'..='z' | 'A'..='Z' | '_' => {
|
||||
read_identifier(&mut chars, initial_len, callback);
|
||||
read_identifier(&mut chars, initial_len, &mut callback);
|
||||
if chars.clone().next() != Some('$') {
|
||||
continue;
|
||||
}
|
||||
|
@ -336,7 +330,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::DollarSign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -348,7 +342,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Dot,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
|
||||
match chars.clone().next().unwrap_or_default() {
|
||||
|
@ -357,22 +351,22 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Asterisk,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
'0'..='9' => {
|
||||
read_integer(&mut chars, initial_len, callback);
|
||||
read_integer(&mut chars, initial_len, &mut callback);
|
||||
if chars.clone().next() == Some('$') {
|
||||
skip_char_and_emit(
|
||||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::DollarSign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
}
|
||||
'a'..='z' | 'A'..='Z' | '_' => {
|
||||
read_identifier(&mut chars, initial_len, callback);
|
||||
read_identifier(&mut chars, initial_len, &mut callback);
|
||||
if chars.clone().next() != Some('$') {
|
||||
continue;
|
||||
}
|
||||
|
@ -380,7 +374,7 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::DollarSign,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
|
@ -396,11 +390,11 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::QuestionMark,
|
||||
callback,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
'a'..='z' | 'A'..='Z' | '_' => {
|
||||
read_identifier(&mut chars, initial_len, callback);
|
||||
read_identifier(&mut chars, initial_len, &mut callback);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -416,7 +410,12 @@ pub trait HasFormatSpecifier: AstToken {
|
|||
// Escaped format end specifier, `}}`
|
||||
continue;
|
||||
}
|
||||
skip_char_and_emit(&mut chars, initial_len, FormatSpecifier::Close, callback);
|
||||
skip_char_and_emit(
|
||||
&mut chars,
|
||||
initial_len,
|
||||
FormatSpecifier::Close,
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
while let Some(next_char) = chars.clone().next() {
|
||||
|
|
Loading…
Reference in a new issue