Skip to content

add preference page to format on save (only full file)#451

Open
fabrizioiannetti wants to merge 1 commit intoeclipse-corrosion:masterfrom
fabrizioiannetti:format_on_save
Open

add preference page to format on save (only full file)#451
fabrizioiannetti wants to merge 1 commit intoeclipse-corrosion:masterfrom
fabrizioiannetti:format_on_save

Conversation

@fabrizioiannetti
Copy link
Copy Markdown

rust-analyzer currently does not support range formatting as reported in the capabilites:

"capabilities":{
...
"documentFormattingProvider":true,
"documentRangeFormattingProvider":false,
...

leave the (disabled) preference, to be activated when rust-analyzer supports it.

Copied and modified from eclipse CDT LSP.

@mickaelistria
Copy link
Copy Markdown
Contributor

Would adding support for documentRangeFormattingProvider in rust-analyzer automatically enable format on save in Corrosion automatically? If so, do you think you'd be capable of fixing that upstream, in rust-analyzer directly, so all IDEs would benefit from it?

@fabrizioiannetti
Copy link
Copy Markdown
Author

Sorry for the late answer, I looked a bit into lsp4e and cdt-lsp and indeed lsp4e looks at the server capabilities and adapts the request accordingly (e.g. the range format might actually do a full-file format).

CDT seems to have the same approach as you suggested: implement both and let lsp4e/the language server take care of adapting the request.

I will enable both options so that once rust-analyzer supports range formatting it will be supported automatically.
Implementing it in rust-analyzer may be beyond what my time/knowledge allows :-), seems to be in the work though:

rust-analyzer.rustfmt.rangeFormatting.enable

Default: false

Enables the use of rustfmt's unstable range formatting command for the textDocument/rangeFormatting request. The rustfmt option is unstable and only available on a nightly build.

I'll give a try to the nightly build.

@fabrizioiannetti fabrizioiannetti changed the title add preference psge to format on save (only full file) add preference page to format on save (only full file) Jun 29, 2025
note that currently rnage-formatting is an unstable feature only
enabled in nightly builds, so lsp4e will automatically map it
to a full file format when using the stable toolchain.

Copied and modified from eclipse CDT LSP.
@fabrizioiannetti
Copy link
Copy Markdown
Author

I tried with the rust nightly toolchain and using an LS settings with (from the rust analyzer docs):

{
  "rustfmt": {
	"rangeFormatting": {
	  "enable": true
	}
  }
}

I get range formatting on save (it also requires this fix on lsp4e: eclipse-lsp4e/lsp4e#1294)

I have also updated the changelog.md, but the jenkins run fails because apparently gdb is missing from the test image, not sure how to address this.

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