Skip to content

Commit 457ece7

Browse files
committed
fix(emacs): clear diagnostics properly in Flymake
When our Flymake code set diagnostics, it set them for the whole buffer with :range. However, the :range was incorrect; the begin/end points given were for the *stdout* temporary buffer, not for the user's code buffer. This meant that Flymake diagnostics markers were often not removed because they were not inside the range. (stdout is often much smaller than the JavaScript source being linted.) Fix this by using :range with points derived from the correct buffer.
1 parent c9b9bb7 commit 457ece7

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Semantic Versioning.
5050
in the head of a `for` loop. For example, quick-lint-js no longer warns about
5151
`let x; for (let x = 0;;);`.
5252
* Emacs: .el files are now installed in the correct place on Arch Linux, btw.
53+
* Emacs: The Flymake plugin now reliably clears out diagnostics after issues are
54+
fixed. Sticky diagnostics are no more.
5355
* TypeScript support (still experimental):
5456
* A newline after `public`, `protected`, `private`, or `readonly` inside a
5557
class is now interpreted correctly.

plugin/emacs/flymake-quicklintjs.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ REPORT-FN is Flymake's callback."
9696
(point-min) (point-max))))
9797
(if (not (string-empty-p stderr-data))
9898
(flymake-log :warning "%S" stderr-data))))
99-
(with-current-buffer stdout-buf
100-
(let ((diags (flymake-quicklintjs--make-diagnostics
101-
src-buf
102-
(car (read-from-string
103-
(buffer-substring-no-properties
104-
(point-min) (point-max)))))))
99+
(let ((diags (flymake-quicklintjs--make-diagnostics
100+
src-buf
101+
(car (read-from-string
102+
(with-current-buffer stdout-buf
103+
(buffer-substring-no-properties
104+
(point-min) (point-max))))))))
105+
(with-current-buffer src-buf
105106
(if (or diags (zerop (process-exit-status p)))
106107
(funcall report-fn diags
107108
:region (cons (point-min) (point-max)))

plugin/emacs/test/quicklintjs-test.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ foobar\")((16 . 22) 2 \"E0057\" \"use of undeclared variable: foobar\")(\
110110
(ert-fail "Test timed out waiting for diagnostics."))
111111
;; TODO(strager): Assert specific diagnostics
112112
(while (not (flymake-diagnostics))
113+
(accept-process-output nil 0.01)))))
114+
115+
;; This is a regression test. Buffers were mixed up causing
116+
;; diagnostics after a certain point (usually a few bytes in) to not
117+
;; be cleared.
118+
(ert-deftest quicklintjs-flymake-fixing-error-clears-diagnostics ()
119+
(with-temp-buffer
120+
(javascript-mode)
121+
(insert "/*xxx*/ consol")
122+
(flymake-mode 1)
123+
(add-hook 'flymake-diagnostic-functions #'flymake-quicklintjs nil t)
124+
(flymake-start)
125+
126+
(with-timeout (5
127+
(ert-fail "Test timed out waiting for diagnostics."))
128+
(while (not (flymake-diagnostics))
129+
(accept-process-output nil 0.01)))
130+
131+
(insert "e") ;; Buffer content: /*xxx*/ console
132+
(flymake-start)
133+
134+
(with-timeout (5
135+
(ert-fail "Test timed out waiting for diagnostics to be removed."))
136+
(while (flymake-diagnostics)
113137
(accept-process-output nil 0.01))))))
114138

115139
(defun def-eglot-tests ()

0 commit comments

Comments
 (0)