Everything seems to be working OK now.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
;; Author: Austin Bingham <austin.bingham@gmail.com>
|
||||
;; Version: 0.1
|
||||
;; URL: https://github.com/abingham/flycheck-vale
|
||||
;; Package-Requires: ((emacs "24") (flycheck "0.22") (cl-lib "0.5"))
|
||||
;; Package-Requires: ((emacs "24") (flycheck "0.22"))
|
||||
;;
|
||||
;; This file is not part of GNU Emacs.
|
||||
;;
|
||||
@@ -56,24 +56,39 @@
|
||||
:type '(string)
|
||||
:group 'flycheck-vale)
|
||||
|
||||
(defcustom flycheck-vale-modes '(text-mode markdown-mode rst-mode)
|
||||
"List of major modes in which to apply this checker."
|
||||
:type '(repeat function))
|
||||
|
||||
(defconst flycheck-vale--level-map
|
||||
'(("error" . error)
|
||||
("warning" . warning)))
|
||||
|
||||
(defun flycheck-vale--issue-to-error (result)
|
||||
"Parse a single vale issue into a flycheck error struct.
|
||||
|
||||
We only fill in what we can get from the vale issue directly. The
|
||||
rest (e.g. filename) gets filled in elsewhere."
|
||||
(let-alist result
|
||||
(flycheck-error-new
|
||||
:line .Line
|
||||
:column (elt .Span 0)
|
||||
;; :buffer (current-buffer)
|
||||
;; :filename "TODO"
|
||||
:message .Message
|
||||
;; :checker checker
|
||||
:level (assoc-default .Severity flycheck-vale--level-map 'string-equal 'error))))
|
||||
|
||||
(defun flycheck-vale--output-to-errors (output)
|
||||
"Parse the full JSON output of vale into a sequence of flycheck
|
||||
error structs."
|
||||
(let* ((full-results (json-read-from-string output))
|
||||
|
||||
;; Get the list of issues for each file.
|
||||
(result-vecs (mapcar 'cdr full-results))
|
||||
|
||||
;; Chain all of the issues together. The point here, really, is that we
|
||||
;; don't expect results from more than one file, but we should be
|
||||
;; prepared for the theoretical possibility that the issues are somehow
|
||||
;; split across multiple files. This is basically a punt in lieu of
|
||||
;; more information.
|
||||
(issues (apply 'concatenate 'list (mapcar 'cdr full-results))))
|
||||
(mapcar 'flycheck-vale--issue-to-error issues)))
|
||||
|
||||
@@ -82,6 +97,7 @@
|
||||
|
||||
(let ((orig-buf (current-buffer))
|
||||
(outbuf (get-buffer-create "*flycheck-vale-output*")))
|
||||
|
||||
;; Clear the output buffer
|
||||
(with-current-buffer outbuf
|
||||
(read-only-mode 0)
|
||||
@@ -98,31 +114,29 @@
|
||||
"--output"
|
||||
"JSON")
|
||||
|
||||
;; Parse the content of the output buffer into flycheck error structures,
|
||||
;; passing them to the provided callback.
|
||||
(with-current-buffer outbuf
|
||||
(let ((errors (flycheck-vale--output-to-errors (buffer-string))))
|
||||
;; Fill in the rest of the error struct data.
|
||||
(loop for err in errors do
|
||||
(setf (flycheck-error-buffer err) orig-buf)
|
||||
(setf (flycheck-error-filename err) (buffer-file-name orig-buf))
|
||||
(setf (flycheck-error-checker err) checker))
|
||||
(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)))))
|
||||
|
||||
(defun flycheck-vale--in-supported-mode ()
|
||||
"Determines if buffer is in a mode where vale linting is appropriate."
|
||||
text-mode)
|
||||
|
||||
;;;###autoload
|
||||
(defun flycheck-vale-setup ()
|
||||
"Convenience function to setup the vale flycheck checker.
|
||||
|
||||
This adds a hook to watch for ycmd parse results, and it adds the
|
||||
ycmd checker to the list of flycheck checkers."
|
||||
This adds the vale checker to the list of flycheck checkers."
|
||||
(add-to-list 'flycheck-checkers 'vale))
|
||||
|
||||
(flycheck-define-generic-checker 'vale
|
||||
"A flycheck checker using vale natural language linting."
|
||||
:start #'flycheck-vale--start
|
||||
;; :predicate #'flycheck-vale--in-supported-mode
|
||||
:modes '(text-mode))
|
||||
:modes flycheck-vale-modes)
|
||||
|
||||
(provide 'flycheck-vale)
|
||||
|
||||
|
Reference in New Issue
Block a user