Sunday, August 20, 2017

Ghcid and VS Code

Summary: There's now a Ghcid VS Code addin that gives you red squiggles.

I've been using Ghcid for about 3 years, and VS Code for about 6 months. Ghcid alone is able to display the errors and warnings, and update them whenever you save. In this post I'll show how VS Code users can also click on errors to jump to them, and how to get red squiggles in the text buffer for errors.

Clicking on errors

Using a recent VS Code, if you run ghcid from the terminal window, hold Ctrl and click the filename and it jumps to the right location in the erroneous file.

Red squiggles

Red squiggles are now possible using the haskell-ghcid addin. To get it working:

  • Run ghcid -o ghcid.txt which will produce a file ghcid.txt which updates every time ghcid updates. Running the underlying ghci with -ferror-spans will significantly improve the errors reported.
  • Open ghcid.txt in VS Code as the active editor. Run the VS Code command (Ctrl+Shift+P) named "Watch Ghcid output".

These steps cause the ghcid errors to appear in the VS Code Problems pane, and have red squiggles in the editor. Even though the errors are in the proper problems pane, I still prefer the output provided by the ghcid terminal, so still look at that.

The VS Code addin is not very well polished - but I'm using it on a daily basis.


Yair said...

This is great!
I am using it and am preferring the "problems" pane rather than the terminal because sometimes the errors don't fit in the terminal, which is extremely bothersome when GHC shows type errors before simple name errors..

Neil Mitchell said...

Yair: I've noticed the same thing recently - but it only seems to have started occurring recently - I wonder if it's newer GHC's that report type errors as well as name errors?

Andrew Martin said...

I think that started happening in GHC 8.0. Basically, whenever there's an identifier that's not in scope, it treats it kind of like a typed hole. It would be nice if there were a flag to turn this off with a flag because sometimes it makes errors much worse.

Van'S said...

Have you tried the haskero plugin for vscode ?

Neil Mitchell said...

Andrew: That would be a great improvement - I'm unconvinced it's ever useful.

Van'S: Yes. It didn't really work. My experience with Intero has been exceptionally hit and miss, with sufficient miss that I would never want to rely on it.