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

format selection == doesn't work with rust #4659

Closed
guihao-liang opened this issue Mar 18, 2020 · 8 comments
Closed

format selection == doesn't work with rust #4659

guihao-liang opened this issue Mar 18, 2020 · 8 comments

Comments

@guihao-liang
Copy link

Is your feature request related to a problem? Please describe.
I want to format the selected code with = key for rust lang.

Describe the solution you'd like
select code and use == to format code. In normal mode, just =G to format all. I hope rustfmt can be supported by vscodevim!

Describe alternatives you've considered
I'm using vscode plugin rust-lang.rust and I need to use editor.formatOnSave to format all codes.

@J-Fields
Copy link
Member

This is likely a bug/limitation of the rust plugin. When == is pressed, we just select the line(s) and call editor.action.formatSelection, which is handled by the language server plugin. Can you try calling that command yourself and see what happens?

@guihao-liang
Copy link
Author

This is likely a bug/limitation of the rust plugin. When == is pressed, we just select the line(s) and call editor.action.formatSelection, which is handled by the language server plugin. Can you try calling that command yourself and see what happens?

Thanks for the prompt reply! Could you guide me on how to call that command? Thanks!

@J-Fields
Copy link
Member

Open the command palette (ctrl+shift+P by default) and type "format selection"

@guihao-liang
Copy link
Author

image

Well, there no such operation. That's weird. Is it override by rust-lang.rust?

@guihao-liang
Copy link
Author

I tried with a python file and I can find the format selection command option.

@J-Fields
Copy link
Member

This probably means the rust formatter only supports formatting entire files (I know python's black formatter is the same way). I found rust-lang/rustfmt#434 which led me to rust-lang/rustfmt#3397. In any case, this doesn't seem to be the fault of VSCodeVim so I'll close the issue.

@Anstow
Copy link

Anstow commented Feb 5, 2023

In case others stumble upon this like I have. You can now get this to work using rust-analyzer and opting into the nightly version of rustfmt. You can do this in two steps. Firstly, install the nightly version of rustfmt
$ rustup toolchain install nightly
Secondly, enable this in the rust-analyzer plugin by adding the following to your settings.json:

{
    "rust-analyzer.rustfmt.rangeFormatting.enable": true,
    "rust-analyzer.rustfmt.extraArgs": [
        "+nightly"
    ]
}

@futscdav
Copy link

The option is now spelled "rust-analyzer.rustfmt.enableRangeFormatting": true

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

No branches or pull requests

4 participants