-
-
Notifications
You must be signed in to change notification settings - Fork 19
Only checks syntax on save #29
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
Checking cargo projects (as opposed to single files) can only be performed when files are saved since non-saved files could cause inconsistent state of the project. I.e. you have foo.rs that's not saved but already referenced in main.rs. |
Is there any way to force it to do this? |
I think the problem is that in order to check the file you are editing, we have to pass it somehow to cargo. And, since the file is not saved, cargo should not use the file that's on disk, but the current version that's in your buffer. The usual way to check the buffer you are editing without saving it first in flycheck is to save the current buffer to a temporary file, compile that file, and collect the errors. Now, let's say you are editing As mentionned in #2, we could do that for a top-level crate file that does not have anything pointing to it (though I'm not sure we still do). But that's about it. I don't know of any way right now to tell cargo "build the crate, but use that file for Ultimately, maybe the situation would improve with the Rust Language Server (see rust-lang/rust#31548). But that's still way down the road. |
Thank you for the detailed explanation. |
Here's an idea: if foo.rs contains unsaved changes, could we copy the currently saved version of foo.rs to foo.rs.backup, save foo.rs, then revert afterwards? |
@Wilfred: But will that be fast enough to work in real time? |
@Wilfred I think there may be other unsaved files, too, not only the current one |
@Wilfred I'd rather prefer if Flycheck did not mess with the original file. If something goes wrong while copying files around Flycheck could cause harm and leave the user with much damage. |
@zakkor It'd be fast enough; short-lived changes to files won't be persisted to disk and purely live in-memory. But I find it too risky to add that to Flycheck, and it's too cumbersome to implement completely (see @mkpankov's remark) and safely to support just a single syntax checker. If anyone volunteered they could implement a generic checker around the proposed approach to try it and find out whether it works well but as far as I'm concerned the checker had to live in this extension (and be disabled by default for some time). It's not an approach I'd merge into Flycheck itself. |
Again, if you look at the language server RFC, the goal is to be able to give error feedback of the program that is held in memory of the IDE. That is, the in-buffer version. Using temporary files as a workaround has potentially dangerous consequences, as lunaryorn already stated. Besides, you would hardly gain "error feedback as you type". Compiling crates is far from instantaneous, even if you are compiling only one file. For larger files, you would still need to wait one or two seconds to get your errors back. You could simulate It makes more sense to improve the situation on the compiler's end, rather than workaround it in flycheck. As a bonus, all editors and IDEs would benefit from the improvement! |
@fmdkdd Thanks for the information. I agree that we should wait for improvements in the Rust compiler—which is also a reason why I haven't made stable releases of this extension yet; to me it's just a temporary tool to make Rust at least bearable in Flycheck. I think it's clear that the current compilation model—entire crates as the atomic unit of compilation—doesn't serve editors and IDEs well, so we need additional tooling support from the compiler. The language server surely looks good.; I have no doubt that it's going to be awesome, the Rust community has a track record of delivering great things! |
I am wondering are there any updates on this? Getting syntax checking on the buffer will be a huge boon |
@HemilTheRebel I don't use rust regularly anymore, so I can't say for sure if |
It seems that flycheck-rust only checks syntax when the file is saved, even if the appropriate variables are present in
flycheck-check-syntax-automatically
.Its value is
(save idle-change new-line mode-enabled)
, and yet idle-change and new-line don't trigger the syntax check.The text was updated successfully, but these errors were encountered: