rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

RustAnalzyer as rust formatter in vscode

Open namse opened this issue 2 years ago • 9 comments

Reproduce step

  1. open vs code
  2. copy and paste to new file (ctrl+n)
  3. make sure that selected language is rust in right bottom.
  4. run format (alt+shift+t)

Expected result

  • format with rustfmt by rust-analzyer extension

Actual result

image

vscode doesn't think rust-analzyer is rust formatter.

The previous, deprecated Rust extension supported this formatting. So I hope rust analzyer do this too.

namse avatar Jul 27 '22 09:07 namse

Rust analyzer does support formatting without requiring any configuration. The only times I have seen that error is when rust-analyzer crashed. Could you check the rust analyzer logs in the output pane to see if it crashed?

bjorn3 avatar Jul 27 '22 09:07 bjorn3

Rust analzyer is working with other files which I already saved.

I mean, when that error occurred , I didn't saved the file and just opened new file and then just run format.

Also, I couldn't find rust analzyer in vscode extensions marketplace with search category:formatters rust image

namse avatar Jul 27 '22 09:07 namse

Here is the video about error.

https://user-images.githubusercontent.com/3580430/181212560-0d230d4f-3dfc-4ba4-8f23-cc18a9029760.mp4

There are no output of Rust Analzyer Language Server and Rust Analzyer Client when I run format this time.

namse avatar Jul 27 '22 09:07 namse

r-a doesn't have the formatters tag on the marketplace so that is being filter out by that query

Veykril avatar Jul 27 '22 09:07 Veykril

You are using the Rust (rust-lang.rust) extension? You need the rust-analyzer (rust-lang.rust-analyzer) extension. Don't search for the formatting category. The rust-analyzer extension doesn't have this category listed.

bjorn3 avatar Jul 27 '22 09:07 bjorn3

Ah, the issue is that you are trying to format a file that is not yet on disk, can reproduce that error then. Note that r-a doesn't work at all in files that are not part of the workspace.

Veykril avatar Jul 27 '22 09:07 Veykril

You are using the Rust (rust-lang.rust) extension? You need the rust-analyzer (rust-lang.rust-analyzer) extension. Don't search for the formatting category. The rust-analyzer extension doesn't have this category listed.

I didn't search with that category, vscode suggested to me when I press install formatter... button on error alert.

namse avatar Jul 27 '22 09:07 namse

Ah, the issue is that you are trying to format a file that is not yet on disk, can reproduce that error then. Note that r-a doesn't work at all in files that are not part of the workspace.

That's what i'm saying exactly. Is it intended? There are no plan to support formatting a file which is not yet on disk?

namse avatar Jul 27 '22 09:07 namse

I believe we should be able to support formatting non-indexed files, will have to check but it sounds like something that should be doable since we already format files be feeding rustfmt the source manually.

Veykril avatar Jul 27 '22 09:07 Veykril

I just ran into this problem. rust-analyzer was disabled when I hit "format file", and it didn't show up when I clicked "Install formatter..."

image

The top of the list is the deprecated Rust extension, much like @namse reported.

xobs avatar Apr 05 '23 09:04 xobs