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

Add meson as formatter #261

Merged
merged 5 commits into from
Jan 28, 2025
Merged

Conversation

Totto16
Copy link
Contributor

@Totto16 Totto16 commented Oct 6, 2024

Add meson as formatter

Since meson 1.5.0 meson has a format subcommand, see here

Meson has support for stdin as input since 1.7.0 see here (from the PR from here: mesonbuild/meson#13793)

Notes

This only works since meson 1.7.0 because:

I tested several ways on how to get this to work with >= 1.5.0 and < 1.7.0. But after countless attempts, it didn't work, for some tests see e.g. Totto16/vscode-meson:add_meson_formatter_experiments and in the files utils.ts:55 and utils.ts:104

The main problem with using somethings like "/dev/stdin" "/dev/fd/0" "/proc/self/fd/0" instead of the "-" option only supported since 1.7.0 is the way node child processes handle stdin, see here
image

If anyone has an idea, on how to "polyfill" stdin in >=1.5.0 < 1.7.0 please share it with me 😓

Conclusion

Otherwise this works fine, I tested it with the 1.7.0 release and it works as expected.

Every new setting works as expected, it is a bit annoying, that, if you make some errors in the config, you have to check the output, and don't get intellisense (the error) in the file (if it's in the current workspace) , but thats a "premium" feature and not essential to this PR

TODO

  • Get it to work
  • Wait for the "-" feature to release
  • Add syntax highlighting and maybe also supported values for meson.format files

@tristan957
Copy link
Contributor

Super excited for this!

@Totto16
Copy link
Contributor Author

Totto16 commented Oct 15, 2024

Super excited for this!

Me too, but still figuring out, what the best way of doing this is.

I never managed to create an issue in meson, since some things don't work as expected. With muon you can use "-" as file and it reads from stdin, but with meson this doesn't work yet. I looked into the source code, but it's more complicated, since you have more options, can have multiple file and other more complicated things. It would be nice, If we would Be able to discuss this over there, and see what the best solution for that would be, as for now, in meson v1.5.0 I tried "/dev/stdin" and "/dev/fd/0" But they worked only in a interactive terminal and not in the extension 😓

You are also a contributor in meson, so maybe you have an idea how to do this in a way, that is already supported in v1.5.0 and we should create an issue there, so that it would be supported in a better way, than through a hack 🤔

Edit: I created mesonbuild/meson#13791

@tristan957
Copy link
Contributor

Maybe that is an issue that I can get to in the future.

@Totto16 Totto16 marked this pull request as ready for review December 9, 2024 14:49
@Totto16 Totto16 mentioned this pull request Dec 9, 2024
@Totto16 Totto16 force-pushed the add_meson_formatter branch 5 times, most recently from 61d1fef to de9d504 Compare December 12, 2024 19:33
@Totto16 Totto16 force-pushed the add_meson_formatter branch from de9d504 to 8f9a2f0 Compare January 26, 2025 21:19
@Totto16
Copy link
Contributor Author

Totto16 commented Jan 26, 2025

Since meson v1.7.0 released today, this now works, there are two version checks in the code atm, since only >=1.7.0 supports the needed feature, to use the stdin. I tried several ways to "polyfill" this behavior in >=1.5.0 < 1.7.0 but didn't succeed.

Feel free to try this, it should work as expected.

@tristan957

@Totto16 Totto16 force-pushed the add_meson_formatter branch from 09f3914 to 3d212e8 Compare January 26, 2025 21:39
@tristan957 tristan957 added this pull request to the merge queue Jan 28, 2025
Merged via the queue into mesonbuild:main with commit 869daf4 Jan 28, 2025
6 checks passed
@Totto16 Totto16 deleted the add_meson_formatter branch February 8, 2025 13:08
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