Skip to content

Instantly share code, notes, and snippets.

@mbuczko
Created September 11, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbuczko/f52d12c4164c1591c12977ba98a92254 to your computer and use it in GitHub Desktop.
Save mbuczko/f52d12c4164c1591c12977ba98a92254 to your computer and use it in GitHub Desktop.
flycheck-parse-cargo-rustc
(defun flycheck-parse-cargo-rustc (output checker buffer)
"Parse Cargo errors from OUTPUT and return a list of `flycheck-error'.
CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
the BUFFER that was checked respectively.
The expected format for OUTPUT is a mix of plain text lines and
JSON lines. This function ignores the plain text lines and
parses only JSON lines. Each JSON line is expected to be a JSON
object that represents a message from Cargo. The format of
messages emitted by Cargo is described in cargo's
machine_message.rs at URL `https://git.io/vh24R'."
(let ((errors))
(dolist (msg (flycheck-parse-json output))
(let-alist msg
;; Errors and warnings from rustc are wrapped by cargo, so we filter and
;; unwrap them, and delegate the actual construction of `flycheck-error'
;; objects to `flycheck-parse-rustc-diagnostic'.
;; Check whether the code is non-nil because Rust≥1.44 includes the
;; warning count upon completion.
(when (and (string= .reason "compiler-message")
(or .message.code
(string-prefix-p "error: expected one of" .message.rendered)))
(push (flycheck-parse-rustc-diagnostic .message checker buffer)
errors))))
(apply #'nconc errors)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment