mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Make helper method less specific
This commit is contained in:
parent
8a92910f97
commit
f458ea15d6
2 changed files with 5 additions and 7 deletions
|
@ -4,7 +4,7 @@ use syntax::{
|
||||||
TextRange, TextSize,
|
TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::node_ext::get_outer_macro_name;
|
use super::node_ext::get_outer_macro;
|
||||||
|
|
||||||
pub fn is_format_string(string: &ast::String) -> bool {
|
pub fn is_format_string(string: &ast::String) -> bool {
|
||||||
// Check if `string` is a format string argument of a macro invocation.
|
// Check if `string` is a format string argument of a macro invocation.
|
||||||
|
@ -16,7 +16,7 @@ pub fn is_format_string(string: &ast::String) -> bool {
|
||||||
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
||||||
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
||||||
(|| {
|
(|| {
|
||||||
let name = get_outer_macro_name(string)?;
|
let name = get_outer_macro(string)?.path()?.segment()?.name_ref()?;
|
||||||
|
|
||||||
if !matches!(
|
if !matches!(
|
||||||
name.text().as_str(),
|
name.text().as_str(),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use parser::T;
|
use parser::T;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasLoopBody, NameRef, PathSegmentKind, VisibilityKind},
|
ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
|
||||||
AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
|
AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -458,9 +458,7 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Pat
|
||||||
Some(paths)
|
Some(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_outer_macro_name(string: &ast::String) -> Option<NameRef> {
|
pub fn get_outer_macro(string: &ast::String) -> Option<MacroCall> {
|
||||||
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
||||||
let name = macro_call.path()?.segment()?.name_ref()?;
|
Some(macro_call)
|
||||||
|
|
||||||
Some(name)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue