mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
8536eb016c
commit
a99a48e786
86 changed files with 3149 additions and 1653 deletions
|
@ -1,7 +1,8 @@
|
|||
//! Tools to work with format string literals for the `format_args!` family of macros.
|
||||
use crate::syntax_helpers::node_ext::macro_call_for_string_token;
|
||||
use syntax::{
|
||||
ast::{self, IsString},
|
||||
AstNode, AstToken, TextRange, TextSize,
|
||||
TextRange, TextSize,
|
||||
};
|
||||
|
||||
pub fn is_format_string(string: &ast::String) -> bool {
|
||||
|
@ -14,8 +15,7 @@ pub fn is_format_string(string: &ast::String) -> bool {
|
|||
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
||||
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
||||
(|| {
|
||||
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
||||
let name = macro_call.path()?.segment()?.name_ref()?;
|
||||
let name = macro_call_for_string_token(string)?.path()?.segment()?.name_ref()?;
|
||||
|
||||
if !matches!(
|
||||
name.text().as_str(),
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
use itertools::Itertools;
|
||||
use parser::T;
|
||||
use syntax::{
|
||||
ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind},
|
||||
AstNode, Preorder, RustLanguage, WalkEvent,
|
||||
ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
|
||||
AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
|
||||
};
|
||||
|
||||
pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
|
||||
|
@ -457,3 +457,8 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Pat
|
|||
.collect();
|
||||
Some(paths)
|
||||
}
|
||||
|
||||
pub fn macro_call_for_string_token(string: &ast::String) -> Option<MacroCall> {
|
||||
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
||||
Some(macro_call)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue