Repository navigation
Replies: 3 comments 6 replies
|
I'm not sure about helix, but in VS Code I had to:
|
|
I’m also using Helix and just thought it would be nice to have a specific range formatting configuration, partially expanding complex code more than the default configuration, so I can easily do stuff like swapping function parameters, and finally collapse them to the default format on save. |
|
For range formatting with rust-analyzer you'll likely need to try nightly rustfmt as it's an unstable feature: ConfigurationMake sure to install the nightly components: rustup toolchain install nightly --component rustfmt(if nightly hasn't already been installed just run Set this in your editor LSP config for rust-analyzer: "rust-analyzer.rustfmt.rangeFormatting.enable": trueAlso, add "rust-analyzer.rustfmt.extraArgs": ["+nightly"]Now you'll need to restart the language server and possibly your editor to make sure it takes effect. Format vs RefactorJust a quick note that "formatting" only changes what your code looks like (e.g. The spacing, indentation and line lengths), if you wanted to swap the parameters of your function that's not considered a formatting action-it's refactoring. If that's what you're interested in then you'll need to look for some semantic code action (you might see this referred to as "assists" in rust-analyzer terminology) not range formatting. |
Uh oh!
There was an error while loading. Please reload this page.
Hello anyone reading this, I was wondering if there is any plans for further development of support range formatting. In the Configuration section of the manual there's a
rust-analyzer.rustfmt.rangeFormatting.enableconfig that enables rustfmt's unstable range formatting for textDocument/rangeFormatting on nightly build. I've enabled this configuration.I'm not sure if it's relevant to this discussion, but I'm using Helix and am trying to format a selection (using
=key bound toformat_selections). When I'm running RA stable, I get the errorNo configured language server supports range formattingwhen trying to format selection, and when I'm using RA nightly (64a1405) the error doesn't pop up but the code I selected doesn't get formatted.Also, I've enabled this in my helix/languages.toml file. But is there a separate place I need to enable this for RA itself? I installed the RA nightly binary, if that's of importance.
By the way, RA is awesome so thank you to all the people who are contributing to it!
All reactions