-
Notifications
You must be signed in to change notification settings - Fork 1.7k
rust-analyzer and real-time linting #4185
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
Comments
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. |
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! |
@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 |
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? |
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
@matklad {
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000
} can become: the solution below is customizable and if the project is very big, the user can simply increase the delay or turn it off completely for performance reasons. (this is all under the assumption that saving the file isn't required for linting) {
"rust-analyzer.autoCheck": "afterDelay",
"rust-analyzer.autoCheckDelay": 1000,
} |
Hi guys, right now I had face that issue, the rust-analyzer does not check linting in realtime, when I run command cargo check it throw error and warning, eventhough I had config rust-analyze.linkedProject and enable autocheckonsave but it not work |
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?
The text was updated successfully, but these errors were encountered: