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

Document unstable project based rust analyzer config to override rustfmt #126

Closed
lukashermansson opened this issue Jul 2, 2024 · 5 comments · Fixed by #127
Closed

Document unstable project based rust analyzer config to override rustfmt #126

lukashermansson opened this issue Jul 2, 2024 · 5 comments · Fixed by #127

Comments

@lukashermansson
Copy link
Contributor

This pr: rust-lang/rust-analyzer#17058 adds support for project based rust-analyzer configuration file.

Adding the below section to rust-analyzer.toml in any leptos project you want to format with leptosfmt:

[rustfmt] 
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]

does in my experience make rust-analyzer use leptosfmt for formatting my specific setup is based on neovim, so not sure if it integrates with other editors.

Not sure if its stable enough to document it as a way to have our editors run leptosfmt. As can be noted in the referenced pr:

We don't promise any stability with this feature yet, any configs exposed may be removed again, the grouping may change etc.

If you feel like its a worthwhile addition to the readme regardless of its stability I could attempt a pr with documentation. For this I suppose I would have to find out under what setups this works with, (calling out to any readers, if you can figure out if this feature is available under your setup it would be awesome)

@bram209
Copy link
Owner

bram209 commented Jul 3, 2024

Hi, I think it would be a good idea to add this to the readme as an alternative way to set up, including an admonition that warns users that this is an experimental feature of rust_analyzer.

When this becomes stable, I would say this is the superior way of setting up leptosfmt (as it is editor agnostic)

@lukashermansson
Copy link
Contributor Author

lukashermansson commented Jul 3, 2024

Hey! thanks for the feedback, sounds like a good plan.

I was able to conclude under what editors this feature seems to currently work under
all with the env configured to have the binary: rust-analyzer 1.81.0-nightly (6292b2a 2024-07-02) available

  • Neovim with lspconfig talking to rust-analyzer - works
  • vscode using the rust-analyzer extension v0.3.2020 - works (I notized some odd behaviour in this setup, restarting the editor did not update the configuration but using the feature "restart rust-analyzer" did apply the config specified in rust-analyzer.toml (maybe it keeps rust-analyzer running in the background even when closing the editor?))
  • rust-rover (Ultimate) 2024.1 - does not respect the configuration. (I think they don't rely on rust-analyzer for their lsp features, so i guess it makes sense why it would not work?)

Any other setup that is common enough to leave a comment about?

If nothing else I will begin drafting a pr with documentation on how to set it up and the caveats surrounding the feature tomorrow!

@bram209
Copy link
Owner

bram209 commented Jul 4, 2024

Hi,

You don't have to mention specific editors, you could place the documentation under "Usage with Rust Analyzer", any editor that uses the new version rust_analyzer LSP will work out of the box. As you mentioned, Rust Rover is an IntelliJ based editor, and they don't use Rust Analyzer but have built their alternative (that does not implement the language server protocol).

@bram209
Copy link
Owner

bram209 commented Jul 4, 2024

That said, here are a few other noteworthy editors that have LSP support (out of my head): Helix, Zed, Lapce, Fleet (Jetbrains editor that does use Rust Analyzer)

@lukashermansson
Copy link
Contributor Author

any editor that uses the new version rust_analyzer LSP will work out of the box.

Yes, that is correct, I was trying to find out if any editor bundles a version that does not have this feature built in already, but that might be overkill, it does feel like the standard is to rely on the rust_analyzer available on the path. It lead to some interesting insights about vscode however so maybe the effort is not completely wasted.

Thanks for the help, expect to see a pr in the next couple of days with additions to the readme on how to set it up using this alternative way.

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 a pull request may close this issue.

2 participants