• Stars
    star
    1,121
  • Rank 39,937 (Top 0.9 %)
  • Language
    Haskell
  • License
    Other
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Very low feature GHCi based IDE

ghcid Hackage version Stackage version 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 provide access to the ghci it starts, 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 stack install ghcid or cabal update && cabal install ghcid to install it as normal. Then run ghcid "--command=ghci Main.hs". 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 you may wish to pass --topmost so the console will 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.

Editor integration

There are a few plugins that integrate Ghcid into editors, notably:

Usage tips

In general, to use ghcid, you first need to get ghci working well for you. In particular, craft a command line or .ghci file such that when you start ghci it has loaded all the files you care about (check :show modules). If you want to use --test check that whatever expression you want to use works in that ghci session. Getting ghci started properly is one of the hardest things of using ghcid, and while ghcid has a lot of defaults for common cases, it doesn't always work out of the box.

Evaluation

Using the ghci session that ghcid manages you can also evaluate expressions:

  • 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).

  • If you pass the --allow-eval flag then comments in the source files such as -- $> expr will run expr after loading - see this blog post for more details. Multiline comments are also supported with the following syntax:

    {- $>
    expr1
    expr2
    ...
    exprN
    <$ -}
    

Expressions that read from standard input are likely to hang, given that Ghcid already uses the standard input to interact with Ghci.

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. Other points in the design space include:

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 arbitrary commands when arbitrary files change.

This project reloads ghci when files loaded by ghci change. If you want a more general mechanism, consider:

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. Another option is to pipe ghcid through source-highlight (ghcid | source-highlight -s haskell -f esc).

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 and 8.2 suffer from bug 10600 which means -fno-code also disables pattern matching warnings. On these versions, either accept no pattern match warnings or use -c to specify a command line to start ghci that doesn't include -fno-code. From GHC 8.4 this problem no longer exists.

I get "During interactive linking, GHCi couldn't find the following symbol"

This problem is a manifestation of GHC bug 8025, which is fixed in GHC 8.4 and above. Ghcid automatically appends -fno-code to the command line, but for older GHC's you can supress that with --test "return ()" (to add a fake test) or -c "ghci ..." to manually specify the command to run.

I only see source-spans or colors on errors/warnings after the first load.

Due to limitations in ghci, these flags are only set after the first load. If you want them to apply from the start, pass them on the command line to ghci with something like -c "ghci -ferror-spans -fdiagnostics-color=always".

I want to match on the file/line/column to get jump-to-error functionality in my editor.

You will variously see file:line:col:message, file:line:col1-col2:msg and file:(line1,col1)-(line2,col2):message, as these are the formats GHC uses. To match all of them you can use a regular expression such as ^(\\S*?):(?|(\\d+):(\\d+)(?:-\\d+)?|\\((\\d+),(\\d+)\\)-\\(\\d+,\\d+\\)):([^\n]*).

What if the error message is too big for my console?

You can let ghcid print more with --no-height-limit. The first error message might end up outside of the console view, so you can use --reverse-errors to flip the order of the errors and warnings. Further error messages are just a scroll away. Finally if you're going to be scrolling, you can achieve a cleaner experience with the --clear flag, which clears the console on reload.

I use Alex (.x) and Happy (.y) files, how can I check them?

Ghcid only notices when the .hs files change. To make it respond to other files you can pass the .x and .y files to --restart, e.g. --restart=myparser.y. As long as you set the initial command to something that runs Happy/Alex (e.g. cabal repl) then when those files change everything will restart, causing the initial command to be rerun.

How do I run pass command arguments with --test?

ghcid ... --test Main.main --setup ":set args myargs"

Why do I get "addWatch: resource exhausted (No space left on device)" or "openFile: resource exhausted (Too many open files)" on my Mac?

The Mac has a fairly low limit on the number of file handles available. You can increase it with: sudo sysctl -w fs.inotify.max_user_watches=262144; sudo sysctl -p

More Repositories

1

hlint

Haskell source code suggestions
Haskell
1,427
star
2

shake

Shake build system
Haskell
744
star
3

hoogle

Haskell API search engine
Haskell
689
star
4

tagsoup

Haskell library for parsing and extracting information from (possibly malformed) HTML/XML documents
Haskell
229
star
5

bake

UNMAINTAINED: Continuous integration server
Haskell
130
star
6

record-dot-preprocessor

A preprocessor for a Haskell record syntax using dot
Haskell
126
star
7

weeder

Detect dead exports or package imports
Haskell
123
star
8

debug

Haskell library for debugging
JavaScript
122
star
9

rattle

Forward build system with speculation and caching
Haskell
101
star
10

spaceleak

Notes on space leaks
Haskell
101
star
11

extra

Extra Haskell functions
Haskell
89
star
12

build-shootout

Comparison of build program expressive power
Haskell
88
star
13

cmdargs

Haskell library for command line argument processing
Haskell
88
star
14

uniplate

Haskell library for simple, concise and fast generic operations.
Haskell
71
star
15

safe

Haskell library for safe (pattern match free) functions
Haskell
45
star
16

ghc-make

An alternative to ghc --make which supports parallel compilation of modules and runs faster when nothing needs compiling.
Haskell
39
star
17

interpret

Rust
37
star
18

neil

General tools for Neil
Haskell
37
star
19

profiterole

GHC prof manipulation script
Haskell
30
star
20

nsis

Haskell DSL for producing Windows Installer using NSIS
Haskell
26
star
21

derive

A Haskell program and library to derive instances for data types
TeX
25
star
22

supero

Haskell optimisation tool based on supercompilation
Haskell
25
star
23

offline-stack

Install Stack without internet access
Haskell
18
star
24

hexml

A bad XML parser
C
18
star
25

catch

Haskell pattern match analsyis checker
Haskell
15
star
26

js-jquery

Haskell library to obtain minified jQuery code
Haskell
9
star
27

rexe

.exe forwarder, to allow replacing binaries on PATH
Haskell
8
star
28

office

Macros for Microsoft Office
VBA
7
star
29

VSHaskell

Visual Studio 2010 addin
C#
7
star
30

record-hasfield

A version of HasField that will be available in future GHC
Haskell
7
star
31

shake-paper

Paper on the new GHC Shake-based build system
HTML
6
star
32

lasagna

Checker for Haskell layering violations
Haskell
5
star
33

guihaskell

A graphical REPL and development environment for Haskell
Haskell
5
star
34

hwwg

Haskell Website Working Group
5
star
35

shake-bazel

Experimenting with Shake and Bazel combined
Haskell
4
star
36

blogs

TeX
4
star
37

haskell-parser

Haskell parser based on that from GHC
Haskell
4
star
38

idris-playground

Playing around with Idris
Idris
4
star
39

proplang

A Haskell library for functional GUI development
Haskell
4
star
40

thesis

My PhD thesis - Transformation and Analysis of Functional Programs
Haskell
3
star
41

js-flot

Haskell library to obtain minified Flot code
Haskell
3
star
42

filepattern

A file path matching library
Haskell
3
star
43

qed

Experiments writing a prover
Haskell
3
star
44

core-playground

Simple Core language for Haskell experiments
Haskell
3
star
45

js-dgtable

Haskell library to obtain minified jquery.dgtable code
JavaScript
3
star
46

neil-check

Run neil and hlint on all my projects
Haskell
3
star
47

shake-examples

3
star
48

proof

Haskell library for writing proofs
Haskell
2
star
49

ci-check

Test the various supported CI's
2
star
50

hogle-dead

This repo has been moved to the master branch of https://github.com/ndmitchell/hoogle.
Haskell
2
star
51

stack-3137

Reproduce https://github.com/commercialhaskell/stack/issues/3137
Haskell
2
star
52

winhaskell

Windows Haskell GUI interpretter
C++
1
star
53

fossilizer

Generate 3D images of fossil bedding surfaces
JavaScript
1
star
54

bug-i386-ghc84

1
star
55

proposition

Haskell library for manipulating propositions.
Haskell
1
star
56

tex2hs

A program to check for type errors in a Latex document
Haskell
1
star
57

ndmitchell

1
star
58

hlint-test

Haskell
1
star
59

ghc-process

Compiling and linking files in a single process using the GHC API
Haskell
1
star
60

shark

A bad replacement for cabal/stack
1
star
61

index-search

Searching compressed text indicies
C
1
star
62

awesomo

Prototype optimiser for Haskell programs
Haskell
1
star
63

ninjasmith

Ninja file generator and tester
Haskell
1
star