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

editor.formatOnSave does not actually format on save with RLS #253

Closed
moxian opened this issue May 28, 2017 · 8 comments
Closed

editor.formatOnSave does not actually format on save with RLS #253

moxian opened this issue May 28, 2017 · 8 comments

Comments

@moxian
Copy link

moxian commented May 28, 2017

Version of VSCode: 1.12.2
Version of the extension: 0.3.14
OS: Win7 64 bit
rls: 0.1.0 (38ca9b7 2017-05-14)

Description:

When using RLS, when I save the file, it does not get autoformatted with rustfmt, despite having "editor.formatOnSave": true in settings.json. Seemingly no attempt is even made to format.
Setting "rust.forceLegacyMode": true (and thus disabling RLS) makes autoformat-on-save work again.

Output of the "Rust logging" channel: Nothing of interest. Saving unformatted file appends no line to it. Trying to save when RLS says "Analysis finished" is the same as when it's still in progress (i.e. no formatting occurs).

DEBUG: Configuration: Rustup: create: sysroot=C:\Users\moxian\.rustup\toolchains\nightly-x86_64-pc-windows-gnu
DEBUG: Configuration: Rustup: updateComponents: this.components=["cargo-x86_64-pc-windows-gnu (default)","rls-x86_64-pc-windows-gnu (installed)","rust-analysis-x86_64-pc-windows-gnu (installed)","rust-docs-x86_64-pc-windows-gnu (default)","rust-mingw-x86_64-pc-windows-gnu (default)","rust-src (installed)","rust-std-aarch64-apple-ios","rust-std-aarch64-linux-android","rust-std-aarch64-unknown-fuchsia","rust-std-aarch64-unknown-linux-gnu","rust-std-arm-linux-androideabi","rust-std-arm-unknown-linux-gnueabi","rust-std-arm-unknown-linux-gnueabihf","rust-std-arm-unknown-linux-musleabi","rust-std-arm-unknown-linux-musleabihf","rust-std-armv7-apple-ios","rust-std-armv7-linux-androideabi","rust-std-armv7-unknown-linux-gnueabihf","rust-std-armv7-unknown-linux-musleabihf","rust-std-armv7s-apple-ios","rust-std-asmjs-unknown-emscripten","rust-std-i386-apple-ios","rust-std-i586-pc-windows-msvc","rust-std-i586-unknown-linux-gnu","rust-std-i686-apple-darwin","rust-std-i686-linux-android","rust-std-i686-pc-windows-gnu","rust-std-i686-pc-windows-msvc","rust-std-i686-unknown-freebsd","rust-std-i686-unknown-linux-gnu","rust-std-i686-unknown-linux-musl","rust-std-mips-unknown-linux-gnu","rust-std-mips-unknown-linux-musl","rust-std-mips64-unknown-linux-gnuabi64","rust-std-mips64el-unknown-linux-gnuabi64","rust-std-mipsel-unknown-linux-gnu","rust-std-mipsel-unknown-linux-musl","rust-std-powerpc-unknown-linux-gnu","rust-std-powerpc64-unknown-linux-gnu","rust-std-powerpc64le-unknown-linux-gnu","rust-std-s390x-unknown-linux-gnu","rust-std-sparc64-unknown-linux-gnu","rust-std-wasm32-unknown-emscripten","rust-std-x86_64-apple-darwin","rust-std-x86_64-apple-ios","rust-std-x86_64-linux-android","rust-std-x86_64-pc-windows-gnu (default)","rust-std-x86_64-pc-windows-msvc","rust-std-x86_64-rumprun-netbsd","rust-std-x86_64-unknown-freebsd","rust-std-x86_64-unknown-fuchsia","rust-std-x86_64-unknown-linux-gnu","rust-std-x86_64-unknown-linux-musl","rust-std-x86_64-unknown-netbsd","rustc-x86_64-pc-windows-gnu (default)",""]
DEBUG: Configuration: Rustup: updatePathToRlsExecutable: rlsInstalled=true
DEBUG: Configuration: Rustup: updatePathToRlsExecutable: rlsPath=C:\Users\moxian\.cargo\bin\rls.EXE
DEBUG: runInRlsMode: rlsPath=C:\Users\moxian\.cargo\bin\rls.EXE
DEBUG: runInRlsMode: env={"RUST_SRC_PATH":"C:\\Users\\moxian\\.rustup\\toolchains\\nightly-x86_64-pc-windows-gnu\\lib\\rustlib\\src\\rust\\src"}
DEBUG: runInRlsMode: args=[]
DEBUG: runInRlsMode: revealOutputChannelOn=3
DEBUG: Language Client Manager: start
@0zAND1z
Copy link

0zAND1z commented May 29, 2017

How exactly did you install the RLS? Could you please mention all the steps, to help further.

@RReverser
Copy link
Contributor

Did you create rls.toml with unstable_features = true as per documentation?

@Jackneill
Copy link

Even if the format works, it does not take rustfmt.toml into account in project root.

@moxian
Copy link
Author

moxian commented Jun 14, 2017

Apologies for the delay. I no longer have access to my rust vscode setup, so I cannot test whether the issue still persists.

@ kggp1995

How exactly did you install the RLS? Could you please mention all the steps, to help further.

I installed rustup via vscode - I got a prompt "You are not running RLS, but it's really good! Try it!", and answered "yes". (I don't remember the exact wording).
I tried reinstalling RLS (with either rustup install --force or cargo install --force - i don't remember exactly), that did not help. I tried setting rust to stable from nightly - that, AFAIR, did not let me run RLS at all.

@RReverser

Did you create rls.toml with unstable_features = true as per documentation?

No, I didnt.
There was no mention of that on the main vscode-rust README.md, and rls-specific docs for vscode-rust have no mention of unstable_features as of now.
If you are talking about RLS documentation, then no, I did not expect that I need to go to RLS github, as the installation of RLS is very easy, and asks me just to press "Yes". Losing format-on-save due to this is unexpected.
Right now I see useRustfmt option added to the docs on RLS. It is still not very discoverable, though.

Regardless, I expect that either useRustfmt = True OR unstable_features = True should be set by default to provide nice user experience (provided those options do work (but they sound like they do)).

Again, I apologize, I cannot check whether the advice in this thread solves the problem. Feel free to close the issue.

@0zAND1z
Copy link

0zAND1z commented Jun 14, 2017

Hi @moxian , thanks for sharing. Here's the quick fix(temporary) that might work in your favor:
Insert the : "rust.formatOnSave": true in your VS Code User Settings(Ctrl+, is the shortcut) =>

settings.json:

// Place your settings in this file to overwrite the default settings
{
   ... // Some other settings
   rust.formatOnSave": true,
   ... // Some other settings
}

Hope this helps. Let us know.

@moxian
Copy link
Author

moxian commented Jun 16, 2017

@kggp1995
"rust.formatOnSave": true does nothing. This seems to not even be a valid key in settings dictionary. I had "editor.formatOnSave": true initially, but that does not work without rls.toml and unstable_features = true there.
I've just reinstalled vscode, and can confirm that setting unstable_features = true in rls.toml fixes the problem. My biggest complain in this situation would be that the documentation for that is terribly hidden.

@RReverser
Copy link
Contributor

@moxian Yeah, RLS is not very stable yet and formatting often corrupted my code so I switched back to Racer + Rustfmt ("legacy") mode. It's kinda unfortunate that this extension already suggests RLS by default without mentioning drawbacks, but then I guess otherwise no one would try RLS and it wouldn't improve.

@KalitaAlexey
Copy link
Member

I believe the new version will remove the problem. I'm about to publish it: #279.
If the problem will happen please reopen the issue.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants