Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/expand_macro.rs')
| -rw-r--r-- | crates/ide/src/expand_macro.rs | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index 418043d679..d6bbf2bf79 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -76,15 +76,17 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< if let Some(item) = ast::Item::cast(node.clone()) { if let Some(def) = sema.resolve_attr_macro_call(&item) { break ( - def.name(db).to_string(), + def.name(db).display(db).to_string(), expand_attr_macro_recur(&sema, &item)?, SyntaxKind::MACRO_ITEMS, ); } } if let Some(mac) = ast::MacroCall::cast(node) { + let mut name = mac.path()?.segment()?.name_ref()?.to_string(); + name.push('!'); break ( - mac.path()?.segment()?.name_ref()?.to_string(), + name, expand_macro_recur(&sema, &mac)?, mac.syntax().parent().map(|it| it.kind()).unwrap_or(SyntaxKind::MACRO_ITEMS), ); @@ -149,9 +151,11 @@ fn _format( _db: &RootDatabase, _kind: SyntaxKind, _file_id: FileId, - _expansion: &str, + expansion: &str, ) -> Option<String> { - None + // remove trailing spaces for test + use itertools::Itertools; + Some(expansion.lines().map(|x| x.trim_end()).join("\n")) } #[cfg(not(any(test, target_arch = "wasm32", target_os = "emscripten")))] @@ -235,7 +239,7 @@ fn main() { } "#, expect![[r#" - bar + bar! 5i64 as _"#]], ); } @@ -252,7 +256,7 @@ fn main() { } "#, expect![[r#" - bar + bar! for _ in 0..42{}"#]], ); } @@ -273,9 +277,8 @@ macro_rules! baz { f$0oo!(); "#, expect![[r#" - foo - fn b(){} - "#]], + foo! + fn b(){}"#]], ); } @@ -294,7 +297,7 @@ macro_rules! foo { f$0oo!(); "#, expect![[r#" - foo + foo! fn some_thing() -> u32 { let a = 0; a+10 @@ -328,16 +331,16 @@ fn main() { } "#, expect![[r#" - match_ast - { - if let Some(it) = ast::TraitDef::cast(container.clone()){} - else if let Some(it) = ast::ImplDef::cast(container.clone()){} - else { - { - continue - } - } - }"#]], + match_ast! + { + if let Some(it) = ast::TraitDef::cast(container.clone()){} + else if let Some(it) = ast::ImplDef::cast(container.clone()){} + else { + { + continue + } + } + }"#]], ); } @@ -358,7 +361,7 @@ fn main() { } "#, expect![[r#" - match_ast + match_ast! {}"#]], ); } @@ -383,7 +386,7 @@ fn main() { } "#, expect![[r#" - foo + foo! { macro_rules! bar { () => { @@ -411,7 +414,7 @@ fn main() { } "#, expect![[r#" - foo + foo! "#]], ); } @@ -433,7 +436,7 @@ fn main() { } "#, expect![[r#" - foo + foo! 0"#]], ); } @@ -451,7 +454,7 @@ fn main() { } "#, expect![[r#" - foo + foo! fn f<T>(_: &dyn ::std::marker::Copy){}"#]], ); } @@ -469,8 +472,17 @@ struct Foo {} "#, expect![[r#" Clone - impl < >core::clone::Clone for Foo< >{} - "#]], + impl < >core::clone::Clone for Foo< >where { + fn clone(&self) -> Self { + match self { + Foo{} + => Foo{} + , + + } + } + + }"#]], ); } @@ -486,8 +498,7 @@ struct Foo {} "#, expect![[r#" Copy - impl < >core::marker::Copy for Foo< >{} - "#]], + impl < >core::marker::Copy for Foo< >where{}"#]], ); } @@ -502,8 +513,7 @@ struct Foo {} "#, expect![[r#" Copy - impl < >core::marker::Copy for Foo< >{} - "#]], + impl < >core::marker::Copy for Foo< >where{}"#]], ); check( r#" @@ -514,8 +524,17 @@ struct Foo {} "#, expect![[r#" Clone - impl < >core::clone::Clone for Foo< >{} - "#]], + impl < >core::clone::Clone for Foo< >where { + fn clone(&self) -> Self { + match self { + Foo{} + => Foo{} + , + + } + } + + }"#]], ); } } |