jpellerin / emacs-crystal-mode

A minimal crystal mode for emacs, based on ruby-mode (of course)
GNU General Public License v3.0
23 stars 13 forks source link

Fix flycheck arguments #12

Open ghost opened 8 years ago

ghost commented 8 years ago

With the new crystal the arguments passed should be probably be compile --no-color --no-codegen instead of compile build --no-build --no-color

However, probably one should use the json output together with json.el or so to get accurate error information

Actually, as a quick hack the following might work

(require 'json)

(flycheck-define-checker crystal-build
  "A Crystal syntax checker using crystal build"
  :command ("crystal"
            "compile"
            "--no-codegen"
            "--no-color"
            "--format" "json"
            source-inplace)
  :error-parser
  (lambda (output checker buffer)
    (mapcar (lambda (err)
              (flycheck-error-new :buffer buffer
                                  :checker checker
                                  :filename (cdr-safe (assoc 'file err))
                                  :line (cdr-safe (assoc 'line err))
                                  :column (cdr-safe (assoc 'column err))
                                  :level 'error
                                  :message (cdr-safe (assoc 'message err))))
            (append nil (json-read-from-string output))))
  :modes crystal-mode
  )
ghost commented 7 years ago

Actually, something changed in the meantime. The command is called "build" again but I need some safeguard against output being an empty string (because json-read-from-string signals an error in that case).

(require 'json)

(flycheck-define-checker crystal-build
  "A Crystal syntax checker using crystal build"
  :command ("crystal"
            "build"
            "--no-codegen"
            "--no-color"
            "--format" "json"
            source-inplace)
  :error-parser
  (lambda (output checker buffer)
    (mapcar (lambda (err)
              (flycheck-error-new :buffer buffer
                                  :checker checker
                                  :filename (cdr-safe (assoc 'file err))
                                  :line (cdr-safe (assoc 'line err))
                                  :column (cdr-safe (assoc 'column err))
                                  :level 'error
                                  :message (cdr-safe (assoc 'message err))))
            (append nil (and output
                             (not (zerop (length output)))
                             (json-read-from-string output)))))
  :modes crystal-mode
  )