-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor and improve macro debugging/general utilities #5949
Comments
As a more x-editor alternative, we can implement a custom "macro explorer" virtual buffer with a special language type, where we can use custom syntax highlighting, assists, etc. That is, the 💡 Explore Macro Call opens a split editor with one-level macro expansion, where there's 💡 Expand on each specific recursive call, which changes the text in-place. |
Actually, I think just "expand macro in-place" code action might improve usability a bunch? |
As a blind user who happened to stumble on this and could certainly have used macro debugging tools the other day, going to just chime in that custom editors are difficult from an accessibility perspective and that the built-in VSCode pieces (generally) just work. That's not to say you can't make an accessible editor, but most of the off-the-shelf things you'd grab off NPM or whatever else will usually be entirely inaccessible because they implement the entire thing with CSS and divs/spans/insert-your-favorite-inaccessible-technique. I'm very definitely a backend guy, so I can't provide an accessible option here I'm afraid, but VSCode had to put a tremendous amount of effort into getting their component to work reliably with screen readers by basically implementing a second mode where the thing is an actual multiline text field, then adding a whole other virtual paging thing on top to deal with some screen reader/chrome bugs that exist for very silly reasons. I think that's both a statement as to the complexity and a possible option being as I think their component is either separated or at least separable from VSCode. Also I think VSCode offers some sort of component library for extension authors that's supposed to be accessible, but i'm not sure on the details. I think my ideal would be some sort of expansion inline, but I haven't given what the UX here would look like much thought and the version I'd want vs. the version someone sighted would want are probably very different. |
Add action to expand a declarative macro once, inline. Fixes #13598 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: ![rust-analyser-feature](https://user-images.githubusercontent.com/10906982/208813167-3123e379-8fd5-4206-a4f4-5af1129565f9.gif) I have 2 questions before this PR can be merged: 1. **Should we rustfmt the output?** The advantage of doing this is neater code. The disadvantages are we'd have to format the whole expr/stmt/block (since there's no point just formatting one part, especially over multiple lines), and maybe it moves the code around more in weird ways. My suggestion here is to start off by not doing any formatting; and if it appears useful we can decide to do formatting in a later release. 2. **Is it worth solving the `$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 existing `expandMacro`/`expandMacroInline` commands; provide some option to allow/disallow `$crate` expanding; or come to some other compromise.
Rust analyzer's
expand macro recursively
command is nice, however, it is also greatly flawed and provides little to no utility for debugging more complex macros. This issue is aimed at refactoring it and turning it into a useful tool.Flaws with expand macro recursively
Proposal for refactoring the command
Instead of a simple text read only editor, we can make use of vsc's custom editor windows extension to make a prettier and more useful editor.
The changes would have to be made in steps:
hir::sema::expand
to give more info about what code came from what binding, i suspect this will be the hardest part.Challenges
So what might it look like? 👀
I am by no means a design guy, and i realize this is a blob of colors, but this is conceptually what it might look like:
If anyone has suggestions then please put them below.
The text was updated successfully, but these errors were encountered: