mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Implicit format args support
This commit is contained in:
parent
5b8e386bae
commit
d2cd30007c
37 changed files with 615 additions and 174 deletions
|
@ -55,8 +55,21 @@ pub(crate) fn goto_definition(
|
|||
Some(RangeInfo::new(link_range, vec![nav]))
|
||||
});
|
||||
}
|
||||
|
||||
if let Some((range, resolution)) =
|
||||
sema.check_for_format_args_template(original_token.clone(), offset)
|
||||
{
|
||||
return Some(RangeInfo::new(
|
||||
range,
|
||||
match resolution {
|
||||
Some(res) => def_to_nav(db, Definition::from(res)),
|
||||
None => vec![],
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
let navs = sema
|
||||
.descend_into_macros(DescendPreference::None, original_token.clone(), offset)
|
||||
.descend_into_macros(DescendPreference::None, original_token.clone())
|
||||
.into_iter()
|
||||
.filter_map(|token| {
|
||||
let parent = token.parent()?;
|
||||
|
@ -809,18 +822,13 @@ mod confuse_index { fn foo(); }
|
|||
fn goto_through_format() {
|
||||
check(
|
||||
r#"
|
||||
//- minicore: fmt
|
||||
#[macro_export]
|
||||
macro_rules! format {
|
||||
($($arg:tt)*) => ($crate::fmt::format($crate::__export::format_args!($($arg)*)))
|
||||
}
|
||||
#[rustc_builtin_macro]
|
||||
#[macro_export]
|
||||
macro_rules! format_args {
|
||||
($fmt:expr) => ({ /* compiler built-in */ });
|
||||
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
|
||||
}
|
||||
pub mod __export {
|
||||
pub use crate::format_args;
|
||||
pub use core::format_args;
|
||||
fn foo() {} // for index confusion
|
||||
}
|
||||
fn foo() -> i8 {}
|
||||
|
@ -2056,6 +2064,20 @@ fn f2() {
|
|||
struct S2;
|
||||
S1::e$0();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn implicit_format_args() {
|
||||
check(
|
||||
r#"
|
||||
//- minicore: fmt
|
||||
fn test() {
|
||||
let a = "world";
|
||||
// ^
|
||||
format_args!("hello {a$0}");
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue