Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Better Rustfmt integration #3

Closed
9 tasks done
nrc opened this issue Sep 27, 2016 · 16 comments
Closed
9 tasks done

Better Rustfmt integration #3

nrc opened this issue Sep 27, 2016 · 16 comments

Comments

@nrc
Copy link
Member

nrc commented Sep 27, 2016

RLS currently supports rudimentary Rustfmt integration. It could be improved a lot:

@KalitaAlexey
Copy link
Contributor

@nrc,
Format On Save is built-in feature in Visual Studio Code.

albel727 pushed a commit to albel727/rls that referenced this issue Apr 28, 2017
Use PathBuf and Path where necessary.
@nrc
Copy link
Member Author

nrc commented May 12, 2017

And other issues:

Formatting is currently behind the 'unstable features' flag, we should fix at least the above two and rust-lang/rustfmt#562, before turning it on by default.

(copied into OP)

@nrc
Copy link
Member Author

nrc commented May 17, 2017

cc rust-lang/rust#42071

nrc added a commit that referenced this issue May 28, 2017
@nrc
Copy link
Member Author

nrc commented May 28, 2017

re formatting on save, @KalitaAlexey is correct. To do it you add the following to setttings.json:

"editor.formatOnSave": true

I feel like we should document this somewhere since it is not obvious.

@Xanewok
Copy link
Member

Xanewok commented May 28, 2017

@nrc This is editor/IDE-specific, so I think it'd be best to add it somewhere in rls_vscode (maybe under a section like Supported Features for VSCode?).

@Xanewok
Copy link
Member

Xanewok commented May 28, 2017

Also I've been thinking about the issue where Rustfmt fails to format the file and doesn't inform the user in a friendly way (you have to check the console for errors now).

We could implement continuous style check that's published with regular diagnostics (but with DiagnosticSeverity.Information severity; enabled via RLS settings?).

An example of how JetBrains IDE (PyCharm) shows style warnings:
pycharm

On fail it could send a window/showMessage to a client with a message saying something along the lines of "Automatic formatting failed. Please resolve all the issues that require manual formatting first.".

Apart from solving the problem, where user doesn't know why the IDE isn't performing the auto-formatting, I think the opt-in continuous style check diagnostics is a neat idea on its own and would benefit users.

Also with regards to formatting on save - maybe we could make this feature editor-agnostic and provide format on save on the server side? I'll have to check if LSP allows for spontaneous (not explicitly requested) actions like that.

@nrc
Copy link
Member Author

nrc commented Jun 16, 2017

I've made formatting a whole file stable, formatting ranges is still unstable

@alexheretic
Copy link
Member

Has there been any progress on range formatting? This is quite a common need when you don't own the project, you want to only format the bits you're touching.

@nrc
Copy link
Member Author

nrc commented Jul 27, 2018

Has there been any progress on range formatting?

Afraid not. It's one of the things I'd like to work on after 1.0

@norru
Copy link

norru commented Jul 28, 2018

Question: it doesn't look like rls loads .rustfmt.toml of the project unless rls has been started from the root directory of the project (ie the one containing .rustfmt.toml). Is this expected? I'm using the Corrosion Eclipse plugin; is it something that needs to be added to the plugin itself?

@nrc
Copy link
Member Author

nrc commented Jul 29, 2018

is it something that needs to be added to the plugin itself?

It should be handled by the RLS, not the plugin. This is probably a bug.

@norru
Copy link

norru commented Jul 30, 2018

Please ignore: I think it was a red herring due to an error in my .rustfmt.toml

@Sakari369
Copy link

Hey, thanks for all the work. Just wondering, should line formatting for ranges work or not ? Should it work by setting the unstable settings to true ? Seems the issues for those are closed, but cannot get it working by default at least with VScode and the Rust (rls) extension.

@alexheretic
Copy link
Member

Range formatting doesn't work and it would be a very nice improvement to have this.

I'm not sure the status of this issue is being tracked very actively. Can rustfmt do this yet?

@Xanewok
Copy link
Member

Xanewok commented Feb 24, 2019

Technically it can, it's just gated behind unstable features flag for Rustfmt:

bors added a commit that referenced this issue Apr 6, 2019
Return only modified lines in formatting responses

Ticks few boxes in #3. (that's an early issue!)
Closes #334.

This is currently based on rust-lang/rustfmt#3424 and so currently blocked until it merges.

Configures Rustfmt to use `EmitMode::ModifiedLines` and parses the response - this should work with both statically-linked and externally provided Rustfmt.

@alexheretic do you think you could take a look and double-check?
@Xanewok
Copy link
Member

Xanewok commented Apr 7, 2019

Last remaining points (only return changed file range and return no-op if nothing changed) were addressed by #1385 and this works as expected. As such, I'm happy to close this tracking issue!

The last remaining thing to keep in mind is that range formatting is still gated behind unstable features but that's tracked upstream at rust-lang/rustfmt#3397.

@Xanewok Xanewok closed this as completed Apr 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants