Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable real-time linting while typing with rust-analyzer in VSCode?

I have rust-analyzer extension in VSCode.

In settings I only changed Rust-analyzer › Check On Save: Command from check to clippy (this shouldn't matter).

Problem is I don't see errors when I type, only after I save.

Typed (no error):

typing

Saved (can see error):

saved

Can it be changed?

like image 619
ZiiMakc Avatar asked Jan 19 '21 22:01

ZiiMakc


People also ask

How to install rust analyzer in Visual Studio Code?

Install the rust-analyzer extension # You can find and install the rust-analyzer extension from within VS Code via the Extensions view ( Ctrl+Shift+X) and searching for 'rust-analyzer'. You should install the Release Version.

Does rust-analyzer support real-time linting?

Rust-analyzer does not support real-time linting (yet?). In short, rust-analyzer essentially runs cargo check. For small projects this can be quite fast. However, as project sizes increase, this can take significantly more time, which makes it unfeasible to check in real-time.

How do I enable linting in Visual Studio Code?

By default, linting for Python is enabled in Visual Studio Code using Pylint, and you can enable other linters of your choice. You can easily enable and disable all linting by using the Python: Enable Linting command.

How do I debug a program in rust?

The rust-analyzer extension has basic debugging support via the Rust Analyzer: Debug command available in the Command Palette ( Ctrl+Shift+P) and the Run|Debug CodeLens in the editor. Let's debug the Hello World program, we created earlier.


1 Answers

Problem is I don't see errors when I type, only after I save.

Rust-analyzer does not support real-time linting (yet?).

In short, rust-analyzer essentially runs cargo check. For small projects this can be quite fast. However, as project sizes increase, this can take significantly more time, which makes it unfeasible to check in real-time.

See also issue #4185 and "Drawbacks" on the "First Release" post.


The next best thing you can do (as you already know), is to use "check on save":

"rust-analyzer.checkOnSave.enable": true

(which is enabled by default in the VSCode extension)

like image 165
vallentin Avatar answered Sep 26 '22 21:09

vallentin