The ghcid package

[Tags:bsd3, library, program, test]

Either "GHCi as a daemon" or "GHC + a bit of an IDE". A very simple Haskell development tool which shows you the errors in your project and updates them whenever you save. Run ghcid --topmost --command=ghci, where --topmost makes the window on top of all others (Windows only) and --command is the command to start GHCi on your project (defaults to ghci if you have a .ghci file, or else to cabal repl).


[Skip to Readme]

Properties

Versions 0.1, 0.1.1, 0.1.3, 0.2, 0.3, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.3.6, 0.4, 0.4.1, 0.4.2, 0.5, 0.5.1, 0.6, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.6.6
Change log CHANGES.txt
Dependencies ansi-terminal, base (==4.*), cmdargs (>=0.10), containers, directory, extra (>=1.2), filepath, fsnotify, process (>=1.1), terminal-size (>=0.3), time, unix, Win32 [details]
License BSD3
Copyright Neil Mitchell 2014-2016
Author Neil Mitchell <ndmitchell@gmail.com>, jpmoresmau
Maintainer Neil Mitchell <ndmitchell@gmail.com>
Category Development
Home page https://github.com/ndmitchell/ghcid#readme
Bug tracker https://github.com/ndmitchell/ghcid/issues
Source repository head: git clone https://github.com/ndmitchell/ghcid.git
Uploaded Fri Nov 11 20:29:06 UTC 2016 by NeilMitchell
Distributions LTSHaskell:0.6.6, NixOS:0.6.6, Stackage:0.6.6, Tumbleweed:0.6.6
Downloads 4073 total (165 in the last 30 days)
Votes
3 []
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for ghcid

Readme for ghcid-0.6.6

ghcid Hackage version Stackage version Linux Build Status Windows Build Status

Either "GHCi as a daemon" or "GHC + a bit of an IDE". To a first approximation, it opens ghci and runs :reload whenever your source code changes, formatting the output to fit a fixed height console. Unlike other Haskell development tools, ghcid is intended to be incredibly simple. In particular, it doesn't integrate with any editors, doesn't depend on GHC the library and doesn't start web servers.

Acknowledgements: This project incorporates significant work from JPMoresmau, who is listed as a co-author.

Using it

Run cabal update && cabal install ghcid to install it as normal. Then run ghcid --height=8 --topmost "--command=ghci Main.hs". The height is the number of lines you are going to resize your console window to (defaults to height of the console). The topmost is to make the window sit above all others, which only works on Windows. The command is how you start your project in ghci. If you omit --command then it will default to stack ghci if you have the stack.yaml file and .stack-work directory, default to ghci if you have a .ghci file in the current directory, and otherwise default to cabal repl.

Personally, I always create a .ghci file at the root of all my projects, which usually reads something like:

:set -fwarn-unused-binds -fwarn-unused-imports
:set -isrc
:load Main

After that, resize your console and make it so you can see it while working in your editor. On Windows the console will automatically sit on top of all other windows. On Linux, you probably want to use your window manager to make it topmost or use a tiling window manager.

What you get

On every save you'll see a list of the errors and warnings in your project. It uses ghci under the hood, so even relatively large projects should update their status pretty quickly. As an example:

Main.hs:23:10:
    Not in scope: `verbosit'
    Perhaps you meant `verbosity' (imported from System.Console.CmdArgs)
Util.hs:18:1: Warning: Defined but not used: `foo'

Or, if everything is good, you see:

All good

Please report any bugs you find.

Ghcid Integration

There are a few tools that integrate Ghcid into editors, see the plugins folder for currently supported integrations.

FAQ

  • This isn't as good as full IDE. I've gone for simplicity over features. It's a point in the design space, but not necessarily the best point in the design space for you. For "real" IDEs see the Haskell wiki.
  • If I delete a file and put it back it gets stuck. Yes, that's a bug in GHCi. If you see GHCi getting confused just kill ghcid and start it again.
  • I want to run my tests when files change. You can pass any ghci expression with the --test flag, e.g. --test=:main, which will be run whenever the code is warning free (or pass --warnings for when the code is merely error free).
  • I want to run arbitrary commands when arbitrary files change. This project reloads ghci when files loaded by ghci change. If you want a more general mechanism something like Steel Overseer will probably work better.
  • I want syntax highlighting in the error messages. One option is to use Neovim or Emacs and run the terminal in a buffer whose file type is set to Haskell.
  • I'm not seeing pattern matching warnings. Ghcid automatically appends -fno-code to the command line, which makes the reload cycle about twice as fast. Unfortunately GHC 8.0 suffers from bug 10600 which means -fno-code also disables pattern matching warnings. Until that GHC bug is fixed either accept no pattern match warnings or use -c to specify a command line to start ghci that doesn't include -fno-code.