Skip to content
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

Improve macro handling #103

Merged
merged 10 commits into from
Jan 26, 2025
Merged

Improve macro handling #103

merged 10 commits into from
Jan 26, 2025

Conversation

PgBiel
Copy link
Contributor

@PgBiel PgBiel commented Jan 26, 2025

Fixes several bugs related to macros, including:

  • A crash when parsing invalid macro signatures (macro fn void thisisinvalid());
  • Hovering on a macro now displays the macro keyword, that is macro int aaa(...) instead of fn int aaa(...) (fixes a regression from Slightly improve function hover #102);
  • Macro return types are now properly parsed and retained (so we can display the return type in the signature on hover);
  • Macro methods are now properly parsed (i.e. macro Abc.name(params) is now parsed and considered for completion, which is invoked as abc.name(...) for an Abc abc variable);
  • Macro trailing @body params are now properly parsed, even when they have arguments (e.g. macro name(; @body(int a, float b))
    • The way this is handled will need some improvements in the future, as for now I'm just encoding this information on the type of the @body variable (would be nice to have a separate field on Variable or Type or something instead), but the current way works as follows: I set @body's type to fn void(int a, float b) as that's how it's used in practice, and later parse the type to retrieve (int a, float b) when displaying it in the signature. Let me know if you'd like any specific change in this regard.
  • Macro signatures are now properly displayed on hover (see screenshots below), even when parameters and return type are empty, making it all look nicer.

Future work

  1. One large problem at the moment is that autocomplete and hover cannot find macros prefixed with @. This is because @ is not considered a valid character in a symbol name during search. While I have made some attempts to work around this and had some success, the changes would be larger than I'd like to include in this PR (and I guess this stuff is being reworked anyway in your other PR), so I left them out for now. I wouldn't consider this a blocker for a release. (Opened an issue for this: Hover and autocomplete can't find macros prefixed with @ #104)
  2. The @body(...) variable will probably need some special-casing to make the code less arbitrary.

Screenshots

hovering over macro testc(; @body(int a, float* b)) displays exactly that
hovering over std::printn is no longer ugly

@pherrymason
Copy link
Owner

Thank you very much! Macro handling have been subpar since the beggining

@pherrymason pherrymason merged commit e358da4 into pherrymason:main Jan 26, 2025
2 checks passed
@PgBiel PgBiel deleted the improve-macros branch January 26, 2025 06:57
@pherrymason pherrymason mentioned this pull request Jan 28, 2025
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants