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

rust-analyzer and real-time linting #4185

Closed
sbromberger opened this issue Apr 28, 2020 · 4 comments
Closed

rust-analyzer and real-time linting #4185

sbromberger opened this issue Apr 28, 2020 · 4 comments

Comments

@sbromberger
Copy link

Sorry if this is a stupid question, but I've been hearing that rust-analyzer is a "drop-in replacement" for rls. However, I can't seem to get the same behavior in between rls and rust-analyzer in vim. I've tried two different LSP clients: ALE and coc.nvim, and both of them show this crucial difference:

With rls, linting is "real-time"- that is, with ALE, I configure it to show me new errors whenever I exit insert mode. I type something, hit , and boom - if there's an error, I see it. I fix the problem, and the error notification goes away.

With rust-analyzer, I have to explicitly save the file before anything is linted. I then fix the problem, and have to save the file again for the error notification to disappear. (In the meantime, if I've removed or added a line, the highlight is now on a completely different line that has no error.)

Is this expected behavior, or am I configuring something incorrectly?

@matklad
Copy link
Member

matklad commented Apr 28, 2020

This is expected behavior. The full explanation can be found here: https://rust-analyzer.github.io/blog/2020/04/20/first-release.html#drawbacks.

We'll fix it eventually, by switching to as-you-type linting, but that's pretty far in the future. At the moment the work-around is to enable auto-save in the editor.

@matklad matklad closed this as completed Apr 28, 2020
@sbromberger
Copy link
Author

Thanks for the confirmation. Auto-save in the editor is not a great option, since I don't necessarily want regular writes to disk / remote network mounts.

I would agree that this is a pretty significant drawback, and one that would preclude use of rust-analyzer as a general LSP server until it's fixed. I'm glad to see that it's on the roadmap, though, but a bit concerned by the statement that it's pretty far in the future. Hopefully rls will still be supported until such time as this is implemented.

Appreciate the quick response!

@oblitum
Copy link
Contributor

oblitum commented Apr 29, 2020

@sbromberger you can have both running at the same time, but it's not light on memory: #1710 (comment). I don't use that anymore, but it worked, coc.nvim with analyzer for anything LSP but diagnostics (you can leave it enabled too), and ALE for diagnostics (I think you may also use coc.nvim here too, just set one coc-extension/server-configuration to not have diagnostics, for example, having both coc-rust-analyzer and coc-rls, disable rust-analyzer.diagnostics.enable/rust-analyzer.rust-analyzer.checkOnSave.enable for the first and disable rust.racer_completion for the latter).

@nikitavoloboev
Copy link

nikitavoloboev commented May 11, 2023

Is this possible to achieve in VSCode Rust Analyser? I read this thread and still confused.

I am coming to Rust from Go/TypeScript where I had linting without manually pressing save and I really miss it in Rust.

I watched this video and in there he had a setup although in Vim that had this behavior. Is it possible to do with rust-analyser already?

Offroaders123 added a commit to Offroaders123/rust_nbt that referenced this issue Dec 18, 2023
Unfortunately it looks like Rust Analyzer doesn't support real-time linting like TypeScript and others do, which is unfortunate. You have to save the file for the changes to appear. I've also noticed before that you don't get linting support when editing an arbitrary `.rs` file outside of a project folder, which is unfortunate too. I like that with TS, you can do Ctrl+N, and demo out something to see what happens without even needing to save the file, nor have a `package.json` or `tsconfig.json` adjacent to it, for the editor linting to work.

https://stackoverflow.com/questions/65800478/how-to-enable-real-time-linting-while-typing-with-rust-analyzer-in-vscode
rust-lang/rust-analyzer#4185
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