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

Feature request: Run check or clippy without saving #6591

Closed
danielhuang opened this issue Nov 19, 2020 · 23 comments
Closed

Feature request: Run check or clippy without saving #6591

danielhuang opened this issue Nov 19, 2020 · 23 comments
Labels
A-diagnostics diagnostics / error reporting S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@danielhuang
Copy link

This would be similar to the feature in IntelliJ Rust called "Run external linter to analyze code on the fly"

@YangJeffrey
Copy link

please add this feature ❤️

@MaximilianHollis
Copy link

This would really speed up development.

@lnicola
Copy link
Member

lnicola commented Nov 19, 2020

You can configure some editors (including Code) to auto-save the edited files. Not sharing on-the-fly diagnostics with the compiler is a known limitation.

@danielhuang
Copy link
Author

Enabling auto save does not appear to trigger checking

@HavishNetla
Copy link

this is the feature that's keeping me on intellij rust

@hf29h8sh321
Copy link

This would be a great feature !

@bjorn3
Copy link
Member

bjorn3 commented Dec 1, 2020

It is impossible to present the rust-analyzer vfs to rustc without a custom rustc driver. Custom rustc drivers require nightly, while rust-analyzer supports stable.

@deontologician
Copy link
Contributor

I wonder how hard it would be to shim clippy lints into rust-analyzer diagnostics directly. clippy only runs on nightly, but maybe with some combination of codegen and some shim for the hir types it would be possible / not a ton of manual porting?

@bjorn3
Copy link
Member

bjorn3 commented Dec 9, 2020

Rustc and rust-analyzer use fundamentally incompatible ways of working. Rust-analyzer is as lazy as possible while rustc is pretty eager. This is the reason rust-analyzer is so much faster than rls. Trying to shoehorn clippy into rust-analyzer would require giving up on the speed of rust-analyzer.

@lnicola lnicola added A-diagnostics diagnostics / error reporting S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Dec 21, 2020
@GopherJ
Copy link

GopherJ commented Jan 17, 2021

Another reason that we need this is:

cargo check is soooooooooooooooooooooo slow:)

which sometimes really drives me crazy that after saving I'll need to wait 10 seconds to be able to see diagnostics

@jonas-schievink
Copy link
Contributor

IntelliJ certainly does not implement its own rustc driver, right? How do they implement this feature? autosave + check-on-save?

@bjorn3
Copy link
Member

bjorn3 commented Feb 10, 2021

I assume they simply already reproduce more of the diagnostics rustc produces in their kotlin code. Other than that they simply run cargo check pretty much the same way as rust-analyzer it seems: https://github.com/intellij-rust/intellij-rust/blob/58079c90c737b5357aadc629fda79c5cc8790760/src/main/kotlin/org/rust/cargo/toolchain/tools/Cargo.kt#L328 They do save all files before running it though: https://github.com/intellij-rust/intellij-rust/blob/118d9d9005c8fa611df6837212c92707d4a09a18/src/main/kotlin/org/rust/ide/annotator/RsExternalLinterUtils.kt#L107

@jonas-schievink
Copy link
Contributor

I've confirmed that configuring VS Code as follows makes this work:

{
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 1000,
    "rust-analyzer.checkOnSave.enable": true
}

Since this issue is not about RLS-like compilation using unsaved files, but about IntelliJ's feature, which works the same way, I'm closing this as fixed (or rather, responsibility of the client, and not something rust-analyzer can do server-side).

@asv7c2
Copy link
Contributor

asv7c2 commented Mar 4, 2021

One problem here, autosave cannot be set per language in vscode.
Maybe add autosave delay for rust analyzer settings?

@Logarithmus
Copy link
Contributor

Logarithmus commented Nov 15, 2021

Another reason that we need this is:

cargo check is soooooooooooooooooooooo slow:)

which sometimes really drives me crazy that after saving I'll need to wait 10 seconds to be able to see diagnostics

@GopherJ you contradict yourself in this comment. You're saying cargo check is slow even when running just on save. Imagine how much more CPU time it will consume if being run continuosly.

I have to use rust-analyzer without checkOnSave because for many projects cargo check is really slow. So running cargo check continuosly would be constantly using 100% of CPU & drain your battery in an hour or so. How come you don't understand that?

This would really speed up development.

@MaximilianHollis it will slow down development, because your computer will become unresponsive due to constant 100% CPU usage. I think we should work more on optimizing rustc (parallelizing this final single-threaded phase is crucial, as well as procedural macros optimizations), as well as reducing dependencies in the most popular crates. After all this hard work we may be able to run cargo check continuosly without needing NASA supercomputer.

@jonas-schievink
Copy link
Contributor

Don't start arguments in the issue tracker please

@rust-lang rust-lang locked and limited conversation to collaborators Nov 15, 2021
@rust-lang rust-lang unlocked this conversation Aug 27, 2022
@jhonpedro
Copy link

One problem here, autosave cannot be set per language in vscode. Maybe add autosave delay for rust analyzer settings?

But you can do it per workspace, I think that this is a good workaround

@nikitavoloboev
Copy link

nikitavoloboev commented May 11, 2023

Coming from #4185

Is this still not possible to do without below hack?

{
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 500,
    "rust-analyzer.checkOnSave.enable": true
}

Which I don't want to run as I run rust code with cargo watch -q -- sh -c "tput reset && cargo run -q".

Anything one can do to help implement this needed feature?

@bjorn3
Copy link
Member

bjorn3 commented May 11, 2023

This needs a rustc change to support loading files from rust-analyzer's VFS instead of the disk.

@nikitavoloboev
Copy link

This needs a rustc change to support loading files from rust-analyzer's VFS instead of the disk

Is there an open issue in rustc about it or should we open it?

@HKalbasi
Copy link
Member

I think you can disable check on save, put cargo watch -q -- sh -c "tput reset && cargo run -q" in a vscode task and rely on problem matcher to show diagnostics.

@nikitavoloboev
Copy link

nikitavoloboev commented May 11, 2023

I want to be using Error Lens extension to see errors inline.

@bjorn3
Copy link
Member

bjorn3 commented May 11, 2023

If you use the $rustc-watch problem matcher on the task, errors should be shown inline. See https://rust-analyzer.github.io/manual.html#compiler-feedback-from-external-commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests