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

rust-analyzer.rustfmt.overrideCommand value format isn't documented #13172

Open
jplatte opened this issue Sep 2, 2022 · 9 comments
Open

rust-analyzer.rustfmt.overrideCommand value format isn't documented #13172

jplatte opened this issue Sep 2, 2022 · 9 comments
Labels
A-documentation docs for rust-analyzer usage/inner working C-enhancement Category: enhancement

Comments

@jplatte
Copy link
Contributor

jplatte commented Sep 2, 2022

The current documentation on this setting is not very clear:

Advanced option, fully override the command rust-analyzer uses for formatting.

From #10826 I gathered that I should be able to set it to an array containing an absolute path to a rustfmt executable, but this just caused rust-analyzer to not format files at all anymore (I set it to my nightly toolchain's rustfmt binary).

Could it be documented how this option is meant to be used? Alternatively, it would be great if I could just tell rust-analyzer to use rustfmt from a different toolchain than what's used for everything else.

@Veykril
Copy link
Member

Veykril commented Sep 2, 2022

can you check the logs for errors? For rustfmt that command really only needs to point to a binary, though the rustc devguide passes an edition as well, you might need to do that too.
Example from the rustc devguide:

   "rust-analyzer.rustfmt.overrideCommand": [
        "./build/$TARGET_TRIPLE/stage0/bin/rustfmt",
        "--edition=2021"
    ],

@jplatte
Copy link
Contributor Author

jplatte commented Sep 2, 2022

Well, now I tried again and it just worked (regardless of whether the edition was passed or not). Can I leave this open as a documentation improvement request?

@jplatte jplatte changed the title rust-analyzer.rustfmt.overrideCommand doesn't seem to work rust-analyzer.rustfmt.overrideCommand value format isn't documented Sep 2, 2022
@Veykril Veykril added the A-documentation docs for rust-analyzer usage/inner working label Sep 2, 2022
@jplatte
Copy link
Contributor Author

jplatte commented Sep 2, 2022

Hm no, it's back to not functioning. No logs to be found other than some initialization logs in the Rust Analyzer Client section.

@Veykril
Copy link
Member

Veykril commented Sep 2, 2022

Do you have the RA_LOG env var overwritten? If not this should at least log an error ... does running rustfmt manually work on the file you are trying to format?

@jplatte
Copy link
Contributor Author

jplatte commented Sep 2, 2022

No, I haven't set RA_LOG. I'll try with manual rustfmt invocation in a bit.

@Veykril
Copy link
Member

Veykril commented Sep 2, 2022

Iirc there is still a bug where very weird whitespace can make rustfmt spit out a warning, exiting successfully without formatting anything. This might be what you are running into, at least I hope that's it 😬.

@jplatte
Copy link
Contributor Author

jplatte commented Oct 21, 2022

Seems to work more reliable now I've enabled it again. So only the documentation is left.

Edit: So it was the edition that sometimes causes rustfmt to fail. I tried it manually, it's async move blocks that are not syntactically valid in Rust 2015.

@andrewbaxter
Copy link

andrewbaxter commented Dec 13, 2022

Just landed here. Yeah, the documentation isn't very informative, I assume since this is only intended to work with rustfmt also.

In short

  • args are an array, or null/absent to use default rustfmt
  • first element is binary
  • other elements are arguments to the binary
  • the source code is passed in via stdin
  • the formatted code is taken from stdout

If this were in the docs it would be awesome.

@andrewbaxter
Copy link

FWIW all error messages refer to rustfmt even if you're not using rustfmt, which can be confusing.

@Veykril Veykril added the C-enhancement Category: enhancement label Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation docs for rust-analyzer usage/inner working C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

3 participants