-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add action to expand a declarative macro once, inline. Fixes #13598 #13810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will take a proper look later but there is no need for this to be a custom command, it would make more sense to implement this as an assist instead
not formatting is okay right now, likewise not fixing the $crate replacement
I'll push a commit to make this an assist (thanks -- didn't know that was an option). Is it worth having a command too to do a recursive inline? I'll start working on replacing |
Just an update - the assist is almost done (just finishing off the tests). There's no point in reviewing most of this because it'll get reverted by changing it to be an assist. Thanks for your patience, and suggestions :) |
cf79357
to
16654ce
Compare
Okay @Veykril I think this is now ready for review. Thanks again :) |
let tok = ctx.token_at_offset().right_biased()?; | ||
|
||
let mut anc = tok.parent_ancestors(); | ||
let (_name, expanded, unexpanded) = loop { | ||
let node = anc.next()?; | ||
if let Some(mac) = ast::MacroCall::cast(node.clone()) { | ||
break ( | ||
mac.path()?.segment()?.name_ref()?.to_string(), | ||
ctx.sema.expand(&mac)?.clone_for_update(), | ||
node, | ||
); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let tok = ctx.token_at_offset().right_biased()?; | |
let mut anc = tok.parent_ancestors(); | |
let (_name, expanded, unexpanded) = loop { | |
let node = anc.next()?; | |
if let Some(mac) = ast::MacroCall::cast(node.clone()) { | |
break ( | |
mac.path()?.segment()?.name_ref()?.to_string(), | |
ctx.sema.expand(&mac)?.clone_for_update(), | |
node, | |
); | |
} | |
}; | |
let unexpanded = ctx.find_node_at_offset::<ast::MacroCall>()?; | |
let expanded = ctx.sema.expand(&mac)?.clone_for_update(); |
small nit, otherwise lgtm |
✌️ @tfpk can now approve this pull request |
@bors r+ |
@Veykril is the CI failure above a known issue? A segfault in vscode doesn't seem like my issue, but wondering if we need to report or something? |
☀️ Test successful - checks-actions |
Is it worth adding this to the change log? |
This will appear on the next release changelog I believe |
Yeah, it will be featured automatically next Monday (as it was merged today, after the release). |
Ah, sorry! Didn't realise this happened after the release. Thanks so much:) |
The gif should ideally have been updated to show that this is an assist, not a command |
I wanted to, but I have this little issue on my system: inline-macro.mp4 |
I can update the gif in the next half hour if that helps? |
This commit adds a new r-a method,
expandMacroInline
, which expands the macro that's currently selected. See #13598 for the most applicable issue; though I suspect it'll resolve part of #5949 and make #11888 significantly easier).The macro works like this:
I have 2 questions before this PR can be merged:
$crate
hygiene issue now? -- I think this PR is usable as of right now for some use-cases; but it is annoying that many common macros (i.e.println!()
,format!()
) can't be expanded further unless the user guesses the correct$crate
value. The trouble with solving that issue is that I think it's complicated and imperfect. If we do solve it; we'd also need to either change the existingexpandMacro
/expandMacroInline
commands; provide some option to allow/disallow$crate
expanding; or come to some other compromise.