Skip to content

Instantly share code, notes, and snippets.

@ifiokjr
Last active November 13, 2021 04:18
Show Gist options
  • Save ifiokjr/5ec27e5d7d4d7bc3752f37d6f6481ec1 to your computer and use it in GitHub Desktop.
Save ifiokjr/5ec27e5d7d4d7bc3752f37d6f6481ec1 to your computer and use it in GitHub Desktop.

Rust analyzer only shows errors on save

The rust analyzer currently only shows errors on save.

Coming from the instant updates of TypeScript in vscode it's quite jarring to make a change and not see the red squiggle error lines disappear.

I've found this post and it seems the issue is jarring for others as well. One interesting counterpoint is made by a user.

The problem is that it is easy (relatively speaking) to create an AST when the code is valid. It is difficult (well, impossible really) to create an AST when the code is invalid. That is to say, there is no valid AST when the code is invalid :-) While you are typing, there are only a few places where the AST is valid. In all other cases you have errors.

So the question is, which errors do you want to display while you are typing? All of them? If so, when you break the AST, the error list could be as long as your arm. And this is the problem I observed when Emacs was trying to do the analysis on every key stroke.

You could just wait until there are no errors. But then you'll never show errors :-) You could wait until the user stopped typing for a significant period of time. But that's just annoying. I want to see the errors... so I stop typing for 200 ms and finally my errors show up?

Without thinking too deeply my solution would be to only show errors on save, but show valid states while typing.

  • If I start with an invalid state, and I make a change that fixes that state, the editor should immediately show me that the code is valid without the need to save.
  • If I go on typing and introduce new invalid states, I shouldn't see these invalid states in the editor.
  • Once I save, if the editor is currently in an invalid state, at this point the errors should be presented to me.

So the suggested solution is to turn on auto-save.

The issue is being tracked here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment