vscode-clangd
vscode-clangd copied to clipboard
expand macros in preview
add the expanded version of a macro to macro preview window e.g.
#define MIN(_x, _y) (((_x) < (_y)) ? (_x) : (_y))
...
/*
currently the macro preview window just shows the macro definition.
instead of the definition it could expand to show the definition and
the expanded macro in preview window. in this case:
MIN(_x, _y) (((_x) < (_y)) ? (_x) : (_y))
->
(((3) < (4)) ? (3) : (4))
*/
z = MIN(3, 4);
Not exactly what you're asking for, but there is an "expand macro" code action for macro calls which replaces the macro call with its expansion. You can use it to look at the expansion, and then "undo" to get back the call.
ahhh nice to know. :+1:
https://github.com/microsoft/vscode-cpptools/issues/4183#:~:text=When%20you%20hover%20over%20FOO%20%28ss%29%20and%20click,you%20clicked%20on%20in%20place%20where%20it%20was%3A
@HighCommander4 Hi, would you guys accept a patch like this: prototype in https://github.com/llvm/llvm-project/compare/main...daiyousei-qz:expand-macro-on-hover
This doesn't work very well with multi-line macro though
Update: Have figured out how to format the expansion
Update2: One caveat is that it can't expand macro in macro arguments
Thanks, I think this is a useful addition to the hover and I would encourage you to upload the patch to Phabricator for further review.
My sense is that a "minimum viable" patch would need:
- Some test cases that exercise the new feature (see
HoverTests.cpp
) - Reasonable behaviour for a variety of types of macros that are used in the wild. By that I mean, it shouldn't crash and it shouldn't produce an unreadable hover card; not producing a macro expansion in some cases is fine (we can expand on those cases in the future).
Linking to @daiyousei-qz's patch implementing this: https://reviews.llvm.org/D127082
Linking to @daiyousei-qz's patch implementing this: https://reviews.llvm.org/D127082
This was actually merged a while ago and will be released with clangd 16. I think the issue can be closed.