emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.04k stars 141 forks source link

flycheck on save #57

Closed Parik27 closed 6 years ago

Parik27 commented 6 years ago

Flycheck on cquery (probably all lsp servers) is too fast. I get an error every time I type a character. I find this functionality very annoying. Is there a way to flycheck only on saving the file?

Parik27 commented 6 years ago

(defun lsp-ui-flycheck-enable (_)
  "Enable flycheck integration for the current buffer."
  (setq-local flycheck-check-syntax-automatically '(mode-enabled save))
  (setq-local flycheck-checker 'lsp-ui)
  (lsp-ui-flycheck-add-mode major-mode)
  (add-to-list 'flycheck-checkers 'lsp-ui)
  (run-with-idle-timer 1000 t
               (lambda () (when (and lsp-ui-flycheck--stale-diagnostics flycheck-mode)
                    (flycheck-buffer)
                    (setq lsp-ui-flycheck--stale-diagnostics nil))))
  (add-hook 'lsp-after-diagnostics-hook (lambda ()
                                          (setq lsp-ui-flycheck--stale-diagnostics t)
                                          ;; (when flycheck-mode
                                          ;;   (flycheck-buffer))
                                          )))

This fixed it.

mkleehammer commented 6 years ago

For posterity: here is what I use. Perhaps lsp-ui-flycheck-live-reporting was added after this issue?

(setq flycheck-check-syntax-automatically '(save mode-enable))
;; Only run flycheck after saving or enabling a mode.

(setq lsp-ui-flycheck-live-reporting nil)
;; Make lsp-ui-flycheck honor flycheck-check-syntax-automatically