Using async call to vale command.
This commit is contained in:
committed by
Austin Bingham
parent
c3f864afd2
commit
dc9f5276ed
@@ -60,6 +60,11 @@
|
|||||||
"List of major modes in which to apply this checker."
|
"List of major modes in which to apply this checker."
|
||||||
:type '(repeat function))
|
:type '(repeat function))
|
||||||
|
|
||||||
|
(defcustom flycheck-vale-output-buffer "*flycheck-vale*"
|
||||||
|
"Buffer where tool output gets written."
|
||||||
|
:type '(string)
|
||||||
|
:group 'flycheck-vale)
|
||||||
|
|
||||||
(defconst flycheck-vale--level-map
|
(defconst flycheck-vale--level-map
|
||||||
'(("error" . error)
|
'(("error" . error)
|
||||||
("warning" . warning)))
|
("warning" . warning)))
|
||||||
@@ -91,39 +96,49 @@ rest (e.g. filename) gets filled in elsewhere."
|
|||||||
(issues (apply 'append (mapcar 'cdr full-results))))
|
(issues (apply 'append (mapcar 'cdr full-results))))
|
||||||
(mapcar 'flycheck-vale--issue-to-error issues)))
|
(mapcar 'flycheck-vale--issue-to-error issues)))
|
||||||
|
|
||||||
|
(defun flycheck-vale--handle-finished (checker callback buf)
|
||||||
|
"Parse the contents of the output buffer into flycheck error
|
||||||
|
structures, attaching CHECKER and BUF to the structures, and
|
||||||
|
passing the results to CALLBACK."
|
||||||
|
(let* ((output (with-current-buffer flycheck-vale-output-buffer (buffer-string)))
|
||||||
|
(errors (flycheck-vale--output-to-errors output)))
|
||||||
|
;; Fill in the rest of the error struct database
|
||||||
|
(cl-loop for err in errors do
|
||||||
|
(setf
|
||||||
|
(flycheck-error-buffer err) buf
|
||||||
|
(flycheck-error-filename err) (buffer-file-name buf)
|
||||||
|
(flycheck-error-checker err) checker))
|
||||||
|
(funcall callback 'finished errors)))
|
||||||
|
|
||||||
|
(defun flycheck-vale--normal-completion? (event)
|
||||||
|
(or (string-equal event "finished\n")
|
||||||
|
(string-match "exited abnormally with code 1.*" event)))
|
||||||
|
|
||||||
(defun flycheck-vale--start (checker callback)
|
(defun flycheck-vale--start (checker callback)
|
||||||
"Run vale on the current buffer's contents with CHECKER, passing the results to CALLBACK."
|
"Run vale on the current buffer's contents with CHECKER, passing the results to CALLBACK."
|
||||||
|
|
||||||
(let ((orig-buf (current-buffer))
|
|
||||||
(outbuf (get-buffer-create "*flycheck-vale-output*")))
|
|
||||||
|
|
||||||
;; Clear the output buffer
|
;; Clear the output buffer
|
||||||
(with-current-buffer outbuf
|
(with-current-buffer (get-buffer-create flycheck-vale-output-buffer)
|
||||||
(read-only-mode 0)
|
(read-only-mode 0)
|
||||||
(erase-buffer))
|
(erase-buffer))
|
||||||
|
|
||||||
;; Run vale
|
(let* ((process-connection-type nil)
|
||||||
(call-process-region
|
(proc (start-process "flycheck-vale-process"
|
||||||
(point-min)
|
flycheck-vale-output-buffer
|
||||||
(point-max)
|
|
||||||
flycheck-vale-program
|
flycheck-vale-program
|
||||||
nil ;; delete
|
|
||||||
outbuf
|
|
||||||
nil ;; display
|
|
||||||
"--output"
|
"--output"
|
||||||
"JSON")
|
"JSON")))
|
||||||
|
(lexical-let ((checker checker)
|
||||||
|
(callback callback)
|
||||||
|
(buf (current-buffer)))
|
||||||
|
(set-process-sentinel
|
||||||
|
proc
|
||||||
|
#'(lambda (process event)
|
||||||
|
(when (flycheck-vale--normal-completion? event)
|
||||||
|
(flycheck-vale--handle-finished checker callback buf)))))
|
||||||
|
|
||||||
;; Parse the content of the output buffer into flycheck error structures,
|
(process-send-region proc (point-min) (point-max))
|
||||||
;; passing them to the provided callback.
|
(process-send-eof proc)))
|
||||||
(with-current-buffer outbuf
|
|
||||||
(let ((errors (flycheck-vale--output-to-errors (buffer-string))))
|
|
||||||
;; Fill in the rest of the error struct data.
|
|
||||||
(cl-loop for err in errors do
|
|
||||||
(setf
|
|
||||||
(flycheck-error-buffer err) orig-buf
|
|
||||||
(flycheck-error-filename err) (buffer-file-name orig-buf)
|
|
||||||
(flycheck-error-checker err) checker))
|
|
||||||
(funcall callback 'finished errors)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun flycheck-vale-setup ()
|
(defun flycheck-vale-setup ()
|
||||||
|
Reference in New Issue
Block a user