Implicit format args support

This commit is contained in:
Lukas Wirth 2023-12-05 15:42:39 +01:00
parent 5b8e386bae
commit d2cd30007c
37 changed files with 615 additions and 174 deletions

View file

@ -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}");
}
"#,
);
}