1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

New Flymake API variable flymake-diagnostic-functions

Lay groundwork for multiple active backends in the same buffer.

Backends are lisp functions called when flymake-mode sees fit.  They
are responsible for examining the current buffer and telling
flymake.el, via return value, if they can syntax check it.
Backends should return quickly and inexpensively, but they are also
passed a REPORT-FN argument which they may or may not call
asynchronously after performing more expensive work.

REPORT-FN's calling convention stipulates that a backend calls it with
a list of diagnostics as argument, or, alternatively, with a symbol
denoting an exceptional situation, usually some panic resulting from a
misconfigured backend.  In keeping with legacy behaviour,
flymake.el's response to a panic is to disable the issuing backend.

The flymake--diag object representing a diagnostic now also keeps
information about its source backend.  Among other uses, this allows
flymake to selectively cleanup overlays based on which backend is
updating its diagnostics.

* lisp/progmodes/flymake-proc.el (flymake-proc--report-fn):
New dynamic variable.
(flymake-proc--process): New variable.
(flymake-can-syntax-check-buffer): Remove.
(flymake-proc--process-sentinel): Simplify.  Use
unwind-protect.  Affect flymake-proc--processes here.
Bind flymake-proc--report-fn.
(flymake-proc--process-filter): Bind flymake-proc--report-fn.
(flymake-proc--post-syntax-check): Delete
(flymake-proc-start-syntax-check): Take mandatory
report-fn.  Rewrite.  Bind flymake-proc--report-fn.
(flymake-proc--process-sentinel): Rewrite and simplify.
(flymake-proc--panic): New helper.
(flymake-proc--start-syntax-check-process): Record report-fn
in process.  Use flymake-proc--panic.
(flymake-proc-stop-all-syntax-checks): Use mapc.  Don't affect
flymake-proc--processes here.  Record interruption reason.
(flymake-proc--init-find-buildfile-dir)
(flymake-proc--init-create-temp-source-and-master-buffer-copy):
Use flymake-proc--panic.
(flymake-diagnostic-functions): Add
flymake-proc-start-syntax-check.
(flymake-proc-compile): Call
flymake-proc-stop-all-syntax-checks with a reason.

* lisp/progmodes/flymake.el (flymake-backends): Delete.
(flymake-check-was-interrupted): Delete.
(flymake--diag): Add backend slot.
(flymake-delete-own-overlays): Take optional filter arg.
(flymake-diagnostic-functions): New user-visible variable.
(flymake--running-backends, flymake--disabled-backends): New
buffer-local variables.
(flymake-is-running): Now a function, not a variable.
(flymake-mode-line, flymake-mode-line-e-w)
(flymake-mode-line-status): Delete.
(flymake-lighter):  flymake's minor-mode "lighter".
(flymake-report): Delete.
(flymake--backend): Delete.
(flymake--can-syntax-check-buffer): Delete.
(flymake--handle-report, flymake--disable-backend)
(flymake--run-backend, flymake--run-backend):  New helpers.
(flymake-make-report-fn): Make a lambda.
(flymake--start-syntax-check): Iterate
flymake-diagnostic-functions.
(flymake-mode): Use flymake-lighter.  Simplify.  Initialize
flymake--running-backends and flymake--disabled-backends.
(flymake-find-file-hook): Simplify.

* test/lisp/progmodes/flymake-tests.el
(flymake-tests--call-with-fixture): Use flymake-is-running the
function.  Check if flymake-mode already active before activating it.
Add a thorough test for flymake multiple backends

* lisp/progmodes/flymake.el (flymake--start-syntax-check):
Don't use condition-case-unless-debug, use condition-case

* test/lisp/progmodes/flymake-tests.el
(flymake-tests--assert-set): New helper macro.
(dummy-backends): New test.
This commit is contained in:
João Távora 2017-09-26 00:45:46 +01:00
parent b2f8b8b47a
commit 94a88c1ae9
3 changed files with 403 additions and 179 deletions

View file

@ -1,4 +1,4 @@
;;; flymake-tests.el --- Test suite for flymake
;;; flymake-tests.el --- Test suite for flymake -*- lexical-binding: t -*-
;; Copyright (C) 2011-2017 Free Software Foundation, Inc.
@ -53,7 +53,7 @@ SEVERITY-PREDICATE is used to setup
(when sev-pred-supplied-p
(setq-local flymake-proc-diagnostic-type-pred severity-predicate))
(goto-char (point-min))
(flymake-mode 1)
(unless flymake-mode (flymake-mode 1))
;; Weirdness here... http://debbugs.gnu.org/17647#25
;; ... meaning `sleep-for', and even
;; `accept-process-output', won't suffice as ways to get
@ -63,7 +63,7 @@ SEVERITY-PREDICATE is used to setup
;; reading an input event, so, as a workaround, use a dummy
;; `read-event' with a very short timeout.
(unless noninteractive (read-event "" nil 0.1))
(while (and flymake-is-running (< (setq i (1+ i)) 10))
(while (and (flymake-is-running) (< (setq i (1+ i)) 10))
(unless noninteractive (read-event "" nil 0.1))
(sleep-for (+ 0.5 flymake-no-changes-timeout)))
(funcall fn)))
@ -130,6 +130,121 @@ SEVERITY-PREDICATE is used to setup
(should (eq 'flymake-error (face-at-point)))
(should-error (flymake-goto-next-error nil t)) ))
(defmacro flymake-tests--assert-set (set
should
should-not)
(declare (indent 1))
`(progn
,@(cl-loop
for s in should
collect `(should (memq ,s ,set)))
,@(cl-loop
for s in should-not
collect `(should-not (memq ,s ,set)))))
(ert-deftest dummy-backends ()
"Test GCC warning via function predicate."
(with-temp-buffer
(cl-labels
((diagnose
(report-fn type words)
(funcall
report-fn
(cl-loop
for word in words
append
(save-excursion
(goto-char (point-min))
(cl-loop while (word-search-forward word nil t)
collect (flymake-make-diagnostic
(current-buffer)
(match-beginning 0)
(match-end 0)
type
(concat word " is wrong")))))))
(error-backend
(report-fn)
(run-with-timer
0.5 nil
#'diagnose report-fn :error '("manha" "prognata")))
(warning-backend
(report-fn)
(run-with-timer
0.5 nil
#'diagnose report-fn :warning '("ut" "dolor")))
(sync-backend
(report-fn)
(diagnose report-fn :note '("quis" "commodo")))
(refusing-backend
(_report-fn)
nil)
(panicking-backend
(report-fn)
(run-with-timer
0.5 nil
report-fn :panic :explanation "The spanish inquisition!"))
(crashing-backend
(_report-fn)
;; HACK: Shoosh log during tests
(setq-local warning-minimum-log-level :emergency)
(error "crashed")))
(insert "Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore
manha aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non prognata
sunt in culpa qui officia deserunt mollit anim id est
laborum.")
(let ((flymake-diagnostic-functions
(list #'error-backend #'warning-backend #'sync-backend
#'refusing-backend #'panicking-backend
#'crashing-backend
)))
(flymake-mode)
;; FIXME: accessing some flymake-ui's internals here...
(flymake-tests--assert-set flymake--running-backends
(#'error-backend #'warning-backend #'panicking-backend)
(#'sync-backend #'crashing-backend #'refusing-backend))
(flymake-tests--assert-set flymake--disabled-backends
(#'crashing-backend)
(#'error-backend #'warning-backend #'sync-backend
#'panicking-backend #'refusing-backend))
(cl-loop repeat 10 while (flymake-is-running)
unless noninteractive do (read-event "" nil 0.1)
do (sleep-for (+ 0.5 flymake-no-changes-timeout)))
(should (eq flymake--running-backends '()))
(flymake-tests--assert-set flymake--disabled-backends
(#'crashing-backend #'panicking-backend)
(#'error-backend #'warning-backend #'sync-backend
#'refusing-backend))
(goto-char (point-min))
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))) ; dolor
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))) ; ut
(flymake-goto-next-error)
(should (eq 'flymake-error (face-at-point))) ; manha
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))) ; Ut
(flymake-goto-next-error)
(should (eq 'flymake-note (face-at-point))) ; quis
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))) ; ut
(flymake-goto-next-error)
(should (eq 'flymake-note (face-at-point))) ; commodo
(flymake-goto-next-error)
(should (eq 'flymake-warning (face-at-point))) ; dolor
(flymake-goto-next-error)
(should (eq 'flymake-error (face-at-point))) ; prognata
(should-error (flymake-goto-next-error nil t))))))
(provide 'flymake-tests)
;;; flymake.el ends here