Skip to content

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

Closed
zakkor opened this issue Aug 11, 2016 · 13 comments
Closed

Only checks syntax on save #29

zakkor opened this issue Aug 11, 2016 · 13 comments
Labels

Comments

@zakkor
Copy link

zakkor commented Aug 11, 2016

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.

@mkpankov
Copy link
Contributor

mkpankov commented Aug 11, 2016

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.

@zakkor
Copy link
Author

zakkor commented Aug 11, 2016

Is there any way to force it to do this?
I think realistically people work only on one file at a time, don't they? IMO it's far more useful and productive to get syntax checking as you type.
Or is it possible to check only when all files in the cargo project (except the one being edited) are saved?

@fmdkdd
Copy link
Member

fmdkdd commented Aug 11, 2016

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 foo.rs and want error feedback without saving. We save the buffer to, say, foo.tmp.rs. Then we call cargo to build the crate. foo is referenced in main.rs, but how do we tell cargo to use foo.tmp.rs instead of foo.rs? We cannot change all the references to foo in the crate.

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 foo.rs instead the one that's on disk". But I don't know all its intricacies, so there may be a way that's not too hackish.

Ultimately, maybe the situation would improve with the Rust Language Server (see rust-lang/rust#31548). But that's still way down the road.

@zakkor
Copy link
Author

zakkor commented Aug 11, 2016

Thank you for the detailed explanation.

@Wilfred
Copy link

Wilfred commented Aug 24, 2016

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?

@zakkor zakkor reopened this Aug 24, 2016
@zakkor
Copy link
Author

zakkor commented Aug 24, 2016

@Wilfred: But will that be fast enough to work in real time?

@mkpankov
Copy link
Contributor

@Wilfred I think there may be other unsaved files, too, not only the current one

@swsnr
Copy link
Contributor

swsnr commented Aug 24, 2016

@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.

@swsnr
Copy link
Contributor

swsnr commented Aug 24, 2016

@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.

@fmdkdd
Copy link
Member

fmdkdd commented Aug 24, 2016

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 idle-change by rolling your own idle timer that automatically saves the buffer and calls flycheck after 0.5 seconds of inactivity. But typing C-x C-s hardly takes longer.

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!

@swsnr
Copy link
Contributor

swsnr commented Aug 24, 2016

@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!

@HemilTheRebel
Copy link

I am wondering are there any updates on this? Getting syntax checking on the buffer will be a huge boon

@fmdkdd
Copy link
Member

fmdkdd commented Dec 13, 2020

@HemilTheRebel I don't use rust regularly anymore, so I can't say for sure if cargo supports checking via stdin. Your best bet is to look into LSP packages and the rust language server.

@fmdkdd fmdkdd closed this as completed Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants