From 4d5eff8c97a21d8bb245fe7f3b9d68efbd29d866 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Thu, 10 May 2018 12:21:29 +0100 Subject: [PATCH] Adjust flymake integration When opening a new file (signalling textDocument/didOpen) it makes sense to call the flymake callback (if it exists) with no diagnostics, just to get rid of that "Wait", since we don't know if later in this callback cycle the server will ever report new diagnostics. * eglot.el (eglot--managed-mode): Don't call flymake-mode or eldoc-mode (eglot--managed-mode-hook): Add them here. (eglot--maybe-activate-editing-mode): Call flymake callback. (eglot--server-textDocument/publishDiagnostics): Set unreported diagnostics to nil if invoking callback. --- lisp/progmodes/eglot.el | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 21ec247967a..f865c22589e 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -798,9 +798,7 @@ DEFERRED is passed to `eglot--request', which see." (add-hook 'completion-at-point-functions #'eglot-completion-at-point nil t) (add-function :before-until (local 'eldoc-documentation-function) #'eglot-eldoc-function) - (add-function :around (local imenu-create-index-function) #'eglot-imenu) - (flymake-mode 1) - (eldoc-mode 1)) + (add-function :around (local imenu-create-index-function) #'eglot-imenu)) (t (remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t) (remove-hook 'after-change-functions 'eglot--after-change t) @@ -818,6 +816,9 @@ DEFERRED is passed to `eglot--request', which see." (when (and (process-live-p proc) (y-or-n-p "[eglot] Kill server too? ")) (eglot-shutdown proc t)))))) +(add-hook 'eglot--managed-mode-hook 'flymake-mode) +(add-hook 'eglot--managed-mode-hook 'eldoc-mode) + (defun eglot--buffer-managed-p (&optional proc) "Tell if current buffer is managed by PROC." (and buffer-file-name (let ((cur (eglot--current-process))) @@ -832,7 +833,8 @@ that case, also signal textDocument/didOpen." (when (eglot--buffer-managed-p proc) (eglot--managed-mode 1) (eglot--signal-textDocument/didOpen) - (flymake-start))) + (flymake-start) + (funcall (or eglot--current-flymake-report-fn #'ignore) nil))) (add-hook 'find-file-hook 'eglot--maybe-activate-editing-mode) @@ -999,11 +1001,11 @@ called interactively." (t :note)) (concat source ": " message))))) into diags - finally (if eglot--current-flymake-report-fn - (funcall eglot--current-flymake-report-fn - diags) - (setq eglot--unreported-diagnostics - diags))))) + finally (cond (eglot--current-flymake-report-fn + (funcall eglot--current-flymake-report-fn diags) + (setq eglot--unreported-diagnostics nil)) + (t + (setq eglot--unreported-diagnostics diags)))))) (t (eglot--message "OK so %s isn't visited" filename))))) @@ -1174,15 +1176,12 @@ Records START, END and PRE-CHANGE-LENGTH locally." (defun eglot-flymake-backend (report-fn &rest _more) "An EGLOT Flymake backend. Calls REPORT-FN maybe if server publishes diagnostics in time." - ;; Maybe call immediately if anything unreported (this will clear - ;; any pending diags) + (setq eglot--current-flymake-report-fn report-fn) + ;; Report anything unreported (when eglot--unreported-diagnostics (funcall report-fn eglot--unreported-diagnostics) (setq eglot--unreported-diagnostics nil)) - ;; Setup so maybe it's called later, too. - (setq eglot--current-flymake-report-fn report-fn) - ;; Take this opportunity to signal a didChange that might eventually - ;; make the server report new diagnostics. + ;; Signal a didChange that might eventually bring new diagnotics (eglot--signal-textDocument/didChange)) (defun eglot-xref-backend () -- 2.39.2