-
Notifications
You must be signed in to change notification settings - Fork 81
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
Feature Request: Support cargo fmt #278
Comments
I've got no objection to changing the default. What I want to ensure is that formatting still runs even when there is no project configuration, instead of erroring out. Would I would expect as a user is that if there is Cargo configuration in the project, then Cargo would be used. Otherwise, rustfmt would be used. This should be possible with a small shell script. As for the working directory issue, try |
This is especially relevant for say, org-babel source blocks that contain Rust code. |
Thank you for the suggestion. Unfortunately, with the configuration of (setf (alist-get 'rustfmt apheleia-formatters)
'("apheleia-from-project-root" "Cargo.lock" "cargo" "--quiet" "fmt" "--" "--quiet" "--emit" "stdout"))) I end up with a formatted copy of the source below the original contents in the file, rather than the original contents of the file modified via the formatter. Anything I'm doing that's obviously incorrect? I'm on the latest version of |
I'm not sure. That looks fine to me, and I tried that formatter definition in my own configuration and it seemed to work properly. |
When combined with |
Erm, that seems crazy. It formats and concatenates all files in a project even when you explicitly ask it to format a single file? Sounds like this needs to be fixed upstream. |
Found this project via a Doom Emacs GitHub Issue that pointed here. Seems like a cool project, so thanks for this contribution to the Emacs ecosystem.
Ideally, I would expect formatting of Rust code to default to using
cargo fmt
. It's the command that therustfmt
documentation recommends running. As documented, this would rely oncargo
to provide the correct edition of Rust to pass along torustc
. For other examples in the Rust ecosystem,rust-analyzer
appears to replicate thecargo
functionality internally.As it currently stands, users need to duplicate their configuration into a
rustfmt.toml
and keep it in sync with theirCargo.toml
. Changing the current default would impact users who write Rust without usingcargo
, but would be more consistent with the ecosystem. If I understand the user guide correctly, I can override the default behavior of callingrustfmt
myself, but I wanted to prompt a discussion on if the current default makes sense.Edit: setting the configuration with
runs in the
src/
folder rather than the root of the project and results inso it would appear to require more effort than changing the configuration alone.
The text was updated successfully, but these errors were encountered: