mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Disable string highlight injection for macros changing string literals
This commit is contained in:
parent
ec07bb98f8
commit
f3b25a6fc8
3 changed files with 31 additions and 29 deletions
|
@ -320,20 +320,37 @@ fn traverse(
|
||||||
element.clone()
|
element.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(token) = element.into_token().and_then(ast::String::cast) {
|
if macro_highlighter.highlight(element_to_highlight.clone()).is_some() {
|
||||||
if token.is_raw() {
|
continue;
|
||||||
if let Some(expanded) = element_to_highlight.as_token() {
|
}
|
||||||
if inject::ra_fixture(hl, sema, token, expanded.clone()).is_some() {
|
|
||||||
|
if let (Some(token), Some(token_to_highlight)) =
|
||||||
|
(element.into_token(), element_to_highlight.as_token())
|
||||||
|
{
|
||||||
|
let string = ast::String::cast(token);
|
||||||
|
let string_to_highlight = ast::String::cast(token_to_highlight.clone());
|
||||||
|
if let Some((string, expanded_string)) = string.zip(string_to_highlight) {
|
||||||
|
if string.is_raw() {
|
||||||
|
if inject::ra_fixture(hl, sema, &string, &expanded_string).is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if macro_highlighter.highlight(element_to_highlight.clone()).is_some() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((mut highlight, binding_hash)) = highlight::element(
|
if let Some((mut highlight, binding_hash)) = highlight::element(
|
||||||
sema,
|
sema,
|
||||||
krate,
|
krate,
|
||||||
|
@ -347,22 +364,6 @@ fn traverse(
|
||||||
|
|
||||||
hl.add(HlRange { range, highlight, binding_hash });
|
hl.add(HlRange { range, highlight, binding_hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,10 @@ use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag};
|
||||||
pub(super) fn highlight_format_string(
|
pub(super) fn highlight_format_string(
|
||||||
stack: &mut Highlights,
|
stack: &mut Highlights,
|
||||||
string: &ast::String,
|
string: &ast::String,
|
||||||
|
expanded_string: &ast::String,
|
||||||
range: TextRange,
|
range: TextRange,
|
||||||
) {
|
) {
|
||||||
if is_format_string(string).is_none() {
|
if is_format_string(expanded_string).is_none() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use ide_db::{
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, IsString},
|
ast::{self, AstNode, IsString},
|
||||||
AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
|
AstToken, NodeOrToken, SyntaxNode, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -22,10 +22,10 @@ use crate::{
|
||||||
pub(super) fn ra_fixture(
|
pub(super) fn ra_fixture(
|
||||||
hl: &mut Highlights,
|
hl: &mut Highlights,
|
||||||
sema: &Semantics<RootDatabase>,
|
sema: &Semantics<RootDatabase>,
|
||||||
literal: ast::String,
|
literal: &ast::String,
|
||||||
expanded: SyntaxToken,
|
expanded: &ast::String,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let active_parameter = ActiveParameter::at_token(sema, expanded)?;
|
let active_parameter = ActiveParameter::at_token(sema, expanded.syntax().clone())?;
|
||||||
if !active_parameter.ident().map_or(false, |name| name.text().starts_with("ra_fixture")) {
|
if !active_parameter.ident().map_or(false, |name| name.text().starts_with("ra_fixture")) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue