Skip to content

Instantly share code, notes, and snippets.

@queertypes
Last active August 29, 2015 14:27
Show Gist options
  • Save queertypes/157699749ea71bae7a16 to your computer and use it in GitHub Desktop.
Save queertypes/157699749ea71bae7a16 to your computer and use it in GitHub Desktop.
Purescript Flychecker

Pulp Flycheck

Defines a Flycheck checker for running the PureScript compiler through Pulp. Based on Bodil's Stokke's: https://github.com/bodil/ohai-emacs/blob/master/modules/ohai-purescript.el#L43

Supports:

  • Standard compiler error messages
  • psc: deprecation messages
  • Syntax errors

Requires, in addition to emacs & flycheck:

  • purescript
  • pulp
  • To be run in a project context, e.g., after pulp init

Source

(require 'purescript-mode)

(flycheck-define-checker
    pulp
  "Use Pulp to flycheck PureScript code."
  :command ("pulp" "--monochrome" "build")
  :error-patterns
  ((error line-start
          (or  (and "Error at " (file-name) " line " line ", column " column
                    (one-or-more not-newline)
                    (message (one-or-more (not (in "*")))))

               (and "psc: " (one-or-more not-newline) "\n"
                    (message (one-or-more not-newline) "\n")
                    "at \"" (file-name) "\" (line " line ", column " column ")")
               (and "Unable to parse module:\n"
                    "  \"" (file-name) "\" (line " line ", column " column "):\n"
                    (message (one-or-more not-newline) "\n"
                             (one-or-more not-newline) "\n"
                             (one-or-more not-newline) "\n"))
               )

          line-end
          ))
  :modes purescript-mode)

Examples

Example: name error

factorial :: Int -> Int
factorial num = go num 1
  where go n acc
          | n <= 0 = acc
          | otherwise = go (wat - 1) (n * acc)
--                          ^  ^

Emacs minibuffer output:

Unknown value wat
See https://github.com/purescript/purescript/wiki/Error-Code-UnknownValue for more information, or to contribute content related to this error.

Example: deprecation error

map :: (a -> b) -> Array a -> Array b
map f [] = []
map f (x:xs) = f x : map f xs'
--     ^  ^

Emacs minibuffer output:

Cons binders are no longer supported. Consider using purescript-lists or purescript-sequences instead.

Example: more deprecation error

map :: (a -> b) -> [a] -> [b]
--                     ^^
map f [] = []
map f (x:xs) = f x : map f xs'

Emacs minibuffer output:

Array notation is no longer supported. Use Array _ instead of [_].

Example: syntax error

datac Color = Red | Green | Blue
--                ^

Emacs minibuffer output:

unexpected Pipe
expecting no indentation or end of input
See https://github.com/purescript/purescript/wiki/Error-Code-ErrorParsingModule for more information, or to contribute content related to this error.

Example: type error

   f' :: Color -> Color
   f' Red   = Green
-- ^
   f' 1 = Blue
   f' Blue  = Red

Emacs minibuffer shows:

Cannot unify type
    Data.Math.Color
  with type
    Prim.Int

See https://github.com/purescript/purescript/wiki/Error-Code-TypesDoNotUnify for more information, or to contribute content related to this error.

Compiling Data.Math
@astahfrom
Copy link

Thank you!
I had to also add this to my Spacemacs config to select the checker:

(add-hook 'purescript-mode-hook
          (lambda ()
            (flycheck-mode)
            (flycheck-select-checker 'pulp)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment