vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

expand macros in preview

Open fneddy opened this issue 3 years ago • 7 comments

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); 

fneddy avatar Jun 28 '21 09:06 fneddy

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.

HighCommander4 avatar Jun 28 '21 18:06 HighCommander4

ahhh nice to know. :+1:

fneddy avatar Jun 29 '21 07:06 fneddy

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

zoumi avatar Mar 28 '22 05:03 zoumi

Can we have expansion information in Hover window? image

zoumi avatar Apr 21 '22 03:04 zoumi

@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

image

daiyousei-qz avatar Jun 04 '22 01:06 daiyousei-qz

This doesn't work very well with multi-line macro though


Update: Have figured out how to format the expansion

image

image


Update2: One caveat is that it can't expand macro in macro arguments

daiyousei-qz avatar Jun 04 '22 03:06 daiyousei-qz

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).

HighCommander4 avatar Jun 06 '22 03:06 HighCommander4

Linking to @daiyousei-qz's patch implementing this: https://reviews.llvm.org/D127082

HighCommander4 avatar Jan 30 '23 01:01 HighCommander4

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.

HighCommander4 avatar Feb 03 '23 05:02 HighCommander4