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

Missing integration of rustfmt #252

Closed
ctron opened this issue Jun 20, 2019 · 17 comments
Closed

Missing integration of rustfmt #252

ctron opened this issue Jun 20, 2019 · 17 comments
Labels
upstream-eclipse Issues requiring work on an Eclipse component (Platform, LSP4E...). Include link to upstream report!

Comments

@ctron
Copy link

ctron commented Jun 20, 2019

To me it looks like currently there is no way to automatically or semi-automatically do source code formatting with rustfmt.

  • My preferred choice would be to run be able to configure rustfmt as a "Save action"
  • At least I would like to be able to press Ctrl+Shift+F (like for Java) and get the code formatted
@mickaelistria
Copy link
Contributor

rustfmt integration is provided by RLS. Ctrl+Shift+F is supposed to be bound to LSP format operation, and it was reported as working in some other tickets. You can also access it from context menu.
About save action, it's something that should probably be requested to RLS or even LSP. I think it's beyond the scope of Corrosion.
However, on possible workaround is to make invocation of rustfmt an external build step in the project. From project settings, you can add some external builder.

@mickaelistria
Copy link
Contributor

mickaelistria commented Jun 21, 2019

On 2nd thoughts, I think "format on save" could be a feature in LSP4E, but that would first require the LS "Format" operation to work.

@mickaelistria mickaelistria added the upstream-eclipse Issues requiring work on an Eclipse component (Platform, LSP4E...). Include link to upstream report! label Jun 21, 2019
@ctron
Copy link
Author

ctron commented Jun 21, 2019

At least for me, manually triggering the code formatting doesn't work.

@mickaelistria
Copy link
Contributor

mickaelistria commented Jun 21, 2019 via email

@ctron
Copy link
Author

ctron commented Jun 21, 2019

rls 1.35.0 (49efc06 2019-04-06)

@norru
Copy link
Contributor

norru commented Jul 2, 2019

integration is provided by RLS. Ctrl+Shift+F is supposed to be bound to LSP format

At the moment Ctrl+Shift+F is unusable for large files as it knackers the syntax highlighting as in #243. Am I the only one seeing this issue (on 3x Linux machines though)?

Extrapolating from @mickaelistria's past comments this seems to be caused by a deeper threading flaw in TM4E.

Having a more robust way of achieving this by rustfmt would be great. At the moment cargo fmt in a terminal is a pain in the neck.

@mickaelistria
Copy link
Contributor

Can you please share such a non-formatted large file that seems to always reproduce the issue for you?

@ctron
Copy link
Author

ctron commented Jul 2, 2019

For me that issue is always the case. Independent of the size of the file.

@norru
Copy link
Contributor

norru commented Jul 2, 2019

Can you please share such a non-formatted large file that seems to always reproduce the issue for you?

It's not project dependent. Every Cargo project I import from GitHub would do. However, here's a link to a random one in which I have just reproduced on (you probably want to fork the repo, clone it and import).

https://github.com/itadinanta/gfx-gtk/blob/master/src/lib.rs

Funny thing, while I was trying this I actually managed to reproduce @ctor's issue where Ctrl+Shift+F doesn't have any effect at all, in another project. It does look like it's an RLS issue though, as both cargo build and cargo fmt complete successfully.

[t=1562068879078] LSP4E to org.eclipse.corrosion.rls:
{"jsonrpc":"2.0","id":"6","method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///[..]/3rdParty/ofx-rs/ofx/src/handle.rs"},"options":{"tabSize":4,"insertSpaces":false}}}
[t=1562068879079] org.eclipse.corrosion.rls to LSP4E:
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":"6"}

I wonder, are most of Corrosion's users building "Hello World" projects, or perhaps my projects are cursed? ;)

@ctor, can you dig out the RLS logs from corrosion and see if something like the one above pops up when you do Ctrl+Shift+F?

@mickaelistria
Copy link
Contributor

I wonder, are most of Corrosion's users building "Hello World" projects,

To be honest, I have the impression you're currently "most of Corrosion's users". Maybe other users face the issue and don't care reporting...

@ctron
Copy link
Author

ctron commented Jul 2, 2019

Ok, checking the logs shows:

[t=1562070660321] LSP4E to org.eclipse.corrosion.rls:
{"jsonrpc":"2.0","id":"11","method":"textDocument/formatting","params":{"textDocument":{"uri":"file:///home/jreimann/Development/workspace-esp32-rust/rust-esp32-hono/src/main.rs"},"options":{"tabSize":4,"insertSpaces":false}}}
[t=1562070660322] org.eclipse.corrosion.rls to LSP4E:
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":"11"}

@norru
Copy link
Contributor

norru commented Jul 2, 2019

@ctor, if you think this the error response is incorrect, could you please file a bug to https://github.com/rust-lang/rls/issues? There is a suspiciously similar one that I've filed months ago: rust-lang/rls#1397

We can probably wait to close this at least until after the RLS crew gives this one some eyeballs.

EDIT: uhm, different issue from the one reported, perhaps I should refrain from hijacking 😛

@norru
Copy link
Contributor

norru commented Jul 2, 2019

Also: @ctor does the situation improve after a cargo clean?

@ctron
Copy link
Author

ctron commented Jul 2, 2019

Still I see one enhancement/fix here. If the RLS reports and error like that, that should pop up in the Eclipse error log.

@norru
Copy link
Contributor

norru commented Jul 2, 2019

Also rust-lang/vscode-rust#534

@ctron
Copy link
Author

ctron commented Oct 6, 2019

Just checked this with Rust 1.38 and Eclipse 2019-09 and it works.

@ctron
Copy link
Author

ctron commented Oct 12, 2019

From my point of view, this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream-eclipse Issues requiring work on an Eclipse component (Platform, LSP4E...). Include link to upstream report!
Projects
None yet
Development

No branches or pull requests

3 participants