Search code examples
emacsspacemacsrust-analyzer

lsp-rust has slow code action and syntax highlight


I use spacemacs with rust layer (lsp-rust-analyzer backend). When I made syntax error, the error highlight appears after a small delay. Then I correct it, the old code action and error highlight sometimes still there, event when no error at current buffer.

I currently deal with it by run command save-buffer to trigger, and lsp doing something trigger the syntax checking again and the code action slowly disappears, annoyingly.

Could you guide me how to change the interval of checking syntax of rust and lsp? Or make a command to trigger the checking syntax manually?


Solution

  • Though I use plain emacs, the configuration should be similar. As far as I remember, lsp-mode uses flycheck for real-time diagnostics/linting.

    Have a look at the variables flycheck-idle-change-delay and flycheck-idle-buffer-switch-delay which can be customized (M-x customize-group "flycheck") . The default is 0.5 seconds which you probably experience as slow (at least I do). A value of 0.1 seconds makes it more 'real time' for me.

    Edit: You might want to ensure that idle-change is included in flycheck-check-syntax-automatically. For me this variable is: (save idle-change new-line mode-enabled)

    Edit 2: The variable flycheck-display-errors-delay might also be of interest to you.