2015-12-02 14:23:39 +00:00
#+TITLE : Haskell layer
2015-06-10 16:44:30 +00:00
2019-05-07 08:53:56 +00:00
#+TAGS : general|layer|programming|pure
2019-05-05 17:26:40 +00:00
2015-06-10 16:44:30 +00:00
[[file:img/haskell.png ]]
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
- [[#features ][Features: ]]
- [[#install ][Install ]]
- [[#layer ][Layer ]]
- [[#dependencies ][Dependencies ]]
- [[#setup-path ][Setup PATH ]]
2019-09-30 04:49:44 +00:00
- [[#choosing-a-backend ][Choosing a backend ]]
2017-05-27 20:57:22 +00:00
- [[#dante ][=dante= ]]
2019-01-22 12:51:24 +00:00
- [[#lsp ][=lsp= ]]
2017-05-22 14:16:12 +00:00
- [[#optional-extras ][Optional extras ]]
- [[#structured-haskell-mode ][structured-haskell-mode ]]
- [[#hindent ][hindent ]]
- [[#key-bindings ][Key bindings ]]
- [[#documentation ][Documentation ]]
- [[#debug ][Debug ]]
- [[#debug-buffer ][Debug Buffer ]]
- [[#repl ][REPL ]]
- [[#cabal-commands ][Cabal commands ]]
- [[#cabal-files ][Cabal files ]]
- [[#refactor ][Refactor ]]
- [[#syntax-checking ][Syntax checking ]]
- [[#flycheck ][Flycheck ]]
- [[#hlint ][HLint ]]
- [[#interactive-haskell-mode ][Interactive haskell-mode ]]
- [[#flymake ][Flymake ]]
- [[#troubleshooting ][Troubleshooting ]]
- [[#faq ][FAQ ]]
- [[#the-repl-doesnt-work ][The REPL doesn't work ]]
- [[#the-repl-is-stuck ][The REPL is stuck ]]
- [[#indentation-doesnt-reset-when-pressing-return-after-an-empty-line ][Indentation doesn't reset when pressing return after an empty line ]]
- [[#flycheck-displays-hlint-warnings-but-not-errors ][Flycheck displays HLint warnings but not errors ]]
2020-07-30 16:13:49 +00:00
- [[#hlint-fails-with-parse-error ][HLint fails with parse error ]]
2017-05-22 14:16:12 +00:00
- [[#i-can-see-highlighted-errors-but-they-dont-appear-in-the-error-list ][I can see highlighted errors but they don't appear in the error list ]]
- [[#flycheck-doesnt-work ][Flycheck doesn't work ]]
- [[#flycheck-doesnt-work-with-stack ][Flycheck doesn't work with =stack= ]]
2017-08-12 03:26:46 +00:00
- [[#the-stack-build-directory-is-wrong ][The =stack= build directory is wrong ]]
2017-05-22 14:16:12 +00:00
- [[#the-project-root-directory-is-not-set-properly ][The Project root directory is not set properly ]]
- [[#haskell-mode-commands-dont-work ][haskell-mode commands don't work ]]
2015-06-10 16:44:30 +00:00
* Description
This layer adds support for the [[https://www.haskell.org/ ][Haskell ]] language.
2015-06-10 21:16:01 +00:00
** Features:
2015-10-25 09:54:56 +00:00
- syntax highlighting for [[https://github.com/haskell/haskell-mode ][haskell source ]], [[https://github.com/haskell/haskell-mode ][cabal files ]], [[https://github.com/bgamari/cmm-mode ][C-- source ]],
2020-08-25 07:38:30 +00:00
- auto-completion with one of the selected backends (=dante= or =lsp= ).
2015-06-10 16:44:30 +00:00
2017-08-12 03:26:46 +00:00
*This layer is under construction, it needs your contributions and bug reports.*
2015-06-10 16:44:30 +00:00
* Install
** Layer
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =haskell= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
2015-10-07 13:58:55 +00:00
** Dependencies
2015-06-10 16:44:30 +00:00
This layer requires some [[https://www.haskell.org/cabal/ ][cabal ]] packages:
2016-06-10 16:53:07 +00:00
- =apply-refact= (required by =hlint-refactor= )
- =hlint= (required by =hlint-refactor= )
- =stylish-haskell= (optional for =haskell-mode= )
- =hasktags= (optional)
- =hoogle= (optional for =haskell-mode= and =helm-hoogle= )
2015-06-10 16:44:30 +00:00
2017-08-12 03:26:46 +00:00
To install them, use the following command (or the =stack= equivalent):
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC sh
2018-09-19 03:54:47 +00:00
$ cabal install apply-refact hlint stylish-haskell hasktags hoogle
2015-06-10 16:44:30 +00:00
#+END_SRC
2015-10-07 13:58:55 +00:00
** Setup PATH
2017-08-12 03:26:46 +00:00
First of all, make sure that your =$PATH= contains the installation path for
2015-10-29 12:41:05 +00:00
Haskell tools like =ghc= , =ghci= etc. It depends on how you have installed
=ghc= , but you can always check it by running =which ghc= in your terminal.
2017-08-12 03:26:46 +00:00
=Stack= users should only add the installation path of =stack= itself. Usually
2019-05-26 20:58:52 +00:00
it's =~/.local/bin= .
2015-10-27 10:59:05 +00:00
2017-08-12 03:26:46 +00:00
Then make sure that your =$PATH= contains the installation path for the =cabal=
2015-10-08 07:08:25 +00:00
packages. If you are using =cabal= it should be =~/.cabal/bin= or
2019-05-26 20:58:52 +00:00
=~/Library/Haskell/bin= (for 'Haskell for Mac' users). If you are using =stack=
2017-08-12 03:26:46 +00:00
then it should be =~/.local/bin= .
2015-10-08 07:08:25 +00:00
2015-10-29 12:41:05 +00:00
For information about setting up =$PATH= , check out the corresponding section in
2015-12-21 13:50:36 +00:00
the FAQ (~SPC h SPC $PATH RET~ ).
2015-10-07 13:58:55 +00:00
2019-09-30 04:49:44 +00:00
** Choosing a backend
2020-08-19 21:11:01 +00:00
First, ensure that you have =auto-completion= layer enabled.
2015-06-10 16:44:30 +00:00
2020-08-19 21:11:01 +00:00
To choose a haskell backend, set the haskell layer variable =haskell-completion-backend= :
#+BEGIN_SRC emacs-lisp
(haskell :variables haskell-completion-backend 'dante)
2015-10-07 13:58:55 +00:00
#+END_SRC
2020-08-25 07:38:30 +00:00
Supported values for =haskell-completion-backend= are =dante= and =lsp= .
2019-09-30 04:49:44 +00:00
2020-08-19 21:11:01 +00:00
If you haven't specified any value for =haskell-completion-backend= ,
2020-08-25 07:38:30 +00:00
=dante= will be used as default backend, unless the layer =lsp= is enabled,
in which case =lsp= is used as default backend.
2019-09-30 04:49:44 +00:00
2018-11-04 17:57:07 +00:00
Backend can be chosen on a per project basis using directory local variables
2020-08-19 21:11:01 +00:00
(files named =.dir-locals.el= at the root of a project). An example of =.dir-locals.el= to use the
2019-09-30 04:49:44 +00:00
=lsp= backend:
2018-11-04 17:57:07 +00:00
#+BEGIN_SRC elisp
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
2019-09-30 04:49:44 +00:00
((haskell-mode (haskell-completion-backend . lsp)))
2018-11-04 17:57:07 +00:00
#+END_SRC
*Note:* you can easily add a directory local variable with ~SPC f v d~ .
2017-05-27 20:57:22 +00:00
*** =dante=
2020-08-27 19:39:03 +00:00
[[https://github.com/jyp/dante ][Dante ]] is a fork of Intero mode which aims exclusively at providing a convenient frontend to GHCi.
2020-08-28 21:26:14 +00:00
2020-08-19 21:11:01 +00:00
It brings features like syntax checking, auto completion, hlint suggestions, automatic error fixing, info at point, definition and use sites.
=dante= works for =cabal= , =nix= , =sytx= , and =stack= users and requires no additional setup.
2017-06-03 05:43:42 +00:00
=dante= requires Emacs 25.
2017-05-27 20:57:22 +00:00
2019-01-22 12:51:24 +00:00
*** =lsp=
2020-08-25 07:38:30 +00:00
=lsp= requires an appropriate installation of =hie= , the official Haskell language server, to work properly.
=hie= is best installed by building it locally as it requires that the same GHC version has been used to
compile your code as has been used for =hie= .
2020-02-10 20:12:50 +00:00
To install it please refer to the official installation instructions [[https://github.com/haskell/haskell-ide-engine#installation ][here ]].
2019-01-22 12:51:24 +00:00
Enabling the =lsp= backend requires the =lsp= layer to be enabled, and provides access to
2019-04-12 19:31:31 +00:00
all the additional =lsp-mode= key bindings. As such it is more of a full backend than just
2019-01-22 12:51:24 +00:00
a completion backend.
2020-08-19 21:11:01 +00:00
Alternatively, you can use [[https://github.com/haskell/haskell-language-server ][Haskell Language Server ]] instead of =hie= (check their docs for installation details).
Haskell Language Server is meant to completely replace =hie= but it is still in early stages of development.
2015-10-25 09:54:56 +00:00
** Optional extras
2017-08-12 03:26:46 +00:00
The Haskell layer supports some extra features, which can be enabled through the
layer variables.
2015-10-07 13:58:55 +00:00
2015-10-25 09:54:56 +00:00
*** structured-haskell-mode
2019-05-26 20:58:52 +00:00
Currently there is no support for [[https://github.com/chrisdone/structured-haskell-mode ][structured-haskell-mode ]], since it doesn't play
2017-08-12 03:26:46 +00:00
very well with non-emacs editing styles ([[https://github.com/chrisdone/structured-haskell-mode/issues/81 ][structured-haskell-mode/#81 ]]). Emacs
editing style users can easily enable it by adding =structured-haskell-mode= to
the list of =dotspacemacs-additional-packages= in your =.spacemacs= file. For
more installation instructions, please refer to the official documentation at
the [[https://github.com/chrisdone/structured-haskell-mode#features ][structured-haskell-mode ]] page. In case you are a non-emacs editing style user
and still want to use =structured-haskell-mode= - use it at your own risk.
2015-10-25 09:54:56 +00:00
2016-02-16 07:56:01 +00:00
Any contributions that will help to solve issues with =structured-haskell-mode=
are warmly welcome!
2015-10-25 09:54:56 +00:00
2015-06-10 16:44:30 +00:00
*** hindent
2017-08-12 03:26:46 +00:00
[[https://github.com/commercialhaskell/hindent ][hindent ]] is an extensible Haskell pretty printer, which lets you reformat your
code. You need to install the executable with =cabal install hindent= or
=stack install hindent= .
2015-06-10 16:44:30 +00:00
2018-01-04 09:25:11 +00:00
To enable it you have to toggle the variable =haskell-enable-hindent= .
2015-06-10 16:44:30 +00:00
2017-04-26 13:50:19 +00:00
See examples [[https://github.com/commercialhaskell/hindent/blob/master/TESTS.md ][here ]].
2015-06-10 16:44:30 +00:00
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
(setq-default dotspacemacs-configuration-layers
'((haskell :variables haskell-enable-hindent t)))
2015-06-10 16:44:30 +00:00
#+END_SRC
* Key bindings
2017-08-12 03:26:46 +00:00
All Haskell specific bindings are prefixed with the major-mode leader ~SPC m~ .
2015-06-10 16:44:30 +00:00
Top-level commands are prefixed by ~SPC m~ :
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-10-12 13:32:05 +00:00
|-------------+---------------------------------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m g g~ | go to definition or tag |
| ~SPC m g i~ | cycle the Haskell import lines or return to point (with prefix arg) |
2016-07-27 20:10:48 +00:00
| ~SPC m F~ | format buffer using haskell-stylish |
| ~SPC m f~ | format declaration using hindent (if enabled) |
2015-06-10 16:44:30 +00:00
** Documentation
Documentation commands are prefixed by ~SPC m h~
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+----------------------------------------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m h d~ | find or generate Haddock documentation for the identifier under the cursor |
| ~SPC m h f~ | do a helm-hoogle lookup |
| ~SPC m h h~ | do a Hoogle lookup |
| ~SPC m h H~ | do a local Hoogle lookup |
| ~SPC m h i~ | gets information for the identifier under the cursor |
| ~SPC m h t~ | gets the type of the identifier under the cursor |
2015-06-10 16:44:30 +00:00
** Debug
Debug commands are prefixed by ~SPC m d~ :
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-10-07 16:59:57 +00:00
|-------------+--------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m d a~ | abandon current process |
| ~SPC m d b~ | insert breakpoint at function |
| ~SPC m d B~ | delete breakpoint |
| ~SPC m d c~ | continue current process |
| ~SPC m d d~ | start debug process, needs to be run first |
| ~SPC m d n~ | next breakpoint |
| ~SPC m d N~ | previous breakpoint |
| ~SPC m d p~ | previous breakpoint |
| ~SPC m d r~ | refresh process buffer |
| ~SPC m d s~ | step into the next function |
| ~SPC m d t~ | trace the expression |
2015-06-10 16:44:30 +00:00
2016-05-18 06:24:39 +00:00
** Debug Buffer
2016-06-10 04:09:42 +00:00
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2016-05-18 06:24:39 +00:00
|-------------+---------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~RET~ | select object at the point |
| ~a~ | abandon current computation |
| ~b~ | break on function |
| ~c~ | continue the current computation |
| ~d~ | delete object at the point |
2017-02-12 18:02:55 +00:00
| ~i~ | step into the next function |
2016-06-23 04:49:42 +00:00
| ~r~ | refresh the debugger buffer |
2017-02-12 18:02:55 +00:00
| ~s~ | go to next step to inspect bindings |
| ~S~ | go to previous step to inspect the bindings |
2016-06-23 04:49:42 +00:00
| ~t~ | trace the expression |
2016-05-18 06:24:39 +00:00
2015-06-10 16:44:30 +00:00
** REPL
REPL commands are prefixed by ~SPC m s~ :
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+-------------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m s b~ | load or reload the current buffer into the REPL |
| ~SPC m s c~ | clear the REPL |
2018-10-19 14:12:33 +00:00
| ~SPC m s s~ | show and switch to the REPL |
| ~SPC m s S~ | show the REPL without switching to it |
2020-01-14 11:47:44 +00:00
| ~C-j~ | switch to next history item |
| ~C-k~ | switch to previous history item |
| ~C-l~ | clear the REPL |
2015-06-10 16:44:30 +00:00
2016-06-10 16:53:07 +00:00
** Cabal commands
2015-06-10 16:44:30 +00:00
Cabal commands are prefixed by ~SPC m c~ :
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2016-06-23 04:49:42 +00:00
|-------------+------------------------------------------------------------|
| ~SPC m c a~ | cabal actions |
| ~SPC m c b~ | build the current cabal project, i.e. invoke =cabal build= |
| ~SPC m c c~ | compile the current project, i.e. invoke =ghc= |
| ~SPC m c v~ | visit the cabal file |
2016-06-03 16:06:52 +00:00
2015-06-10 16:44:30 +00:00
** Cabal files
2017-08-12 03:26:46 +00:00
These commands are available in a cabal file.
2015-06-10 16:44:30 +00:00
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-06-10 16:44:30 +00:00
|-------------+---------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m d~ | add a dependency to the project |
| ~SPC m b~ | go to benchmark section |
| ~SPC m e~ | go to executable section |
| ~SPC m t~ | go to test-suite section |
| ~SPC m m~ | go to exposed modules |
2017-08-12 03:26:46 +00:00
| ~SPC m l~ | go to library section |
2016-06-23 04:49:42 +00:00
| ~SPC m n~ | go to next subsection |
| ~SPC m p~ | go to previous subsection |
| ~SPC m s c~ | clear the REPL |
| ~SPC m s s~ | show the REPL without switching to it |
| ~SPC m s S~ | show and switch to the REPL |
| ~SPC m N~ | go to next section |
| ~SPC m P~ | go to previous section |
| ~SPC m f~ | find or create source-file under the cursor |
2015-10-07 16:59:57 +00:00
2016-05-30 04:07:37 +00:00
** Refactor
Refactor commands are prefixed by ~SPC m r~ :
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2016-05-30 04:07:37 +00:00
|-------------+---------------------------------------------------|
2016-06-23 04:49:42 +00:00
| ~SPC m r b~ | apply all HLint suggestions in the current buffer |
2018-01-24 18:00:15 +00:00
| ~SPC m r i~ | reformat imports from anywhere in the buffer |
2016-06-23 04:49:42 +00:00
| ~SPC m r r~ | apply the HLint suggestion under the cursor |
2016-05-30 04:07:37 +00:00
Only some of the HLint suggestions can be applied.
2016-05-02 22:16:13 +00:00
* Syntax checking
2020-08-25 07:38:30 +00:00
At the moment there are three components, which can indicate
2017-08-12 03:26:46 +00:00
errors and warnings in the code. Those components are:
2020-08-25 07:38:30 +00:00
- dante (via flycheck)
2016-05-06 11:24:12 +00:00
- hlint (via flycheck)
- haskell-mode interactive
2016-06-03 16:06:52 +00:00
2017-08-12 03:26:46 +00:00
Since all of these components can be active at the same time, it can be tricky to
know which component is displaying which message, especially when they disagree,
2020-08-19 21:11:01 +00:00
or if one isn't working. Only flycheck errors (from ghci and hlint) are displayed in
2017-08-12 03:26:46 +00:00
the error list and can be navigated between, using the standard Spacemacs key
bindings (under ~SPC e~ ) even though errors from other modes might highlight the
actual buffer.
2016-05-02 22:16:13 +00:00
2016-06-03 16:06:52 +00:00
** Flycheck
2019-05-26 20:58:52 +00:00
This is the standard Spacemacs way of syntax checking, and it's also the most
2020-08-19 21:11:01 +00:00
elaborate. You need to install the syntax-checking layer first, which will bring flycheck. Please read the
2019-05-26 20:58:52 +00:00
layer's [[https://github.com/syl20bnr/spacemacs/tree/develop/layers/+checkers/syntax-checking ][documentation ]] on how to interact with flycheck.
2016-05-06 11:24:12 +00:00
2020-08-19 21:11:01 +00:00
Flycheck has different Haskell checkers: =haskell-dante= , =haskell-ghc= , =haskell-stack-ghc= and
2017-08-12 03:26:46 +00:00
=haskell-hlint= . Normally it can detect the best one to use automatically, but
2019-05-26 20:58:52 +00:00
if it doesn't work, then you can change it with ~SPC e s~ .
2016-05-02 22:16:13 +00:00
** HLint
2020-07-30 16:13:49 +00:00
[[https://github.com/ndmitchell/hlint ][HLint ]] is a linter for Haskell. It doesn't detect errors (as long as it can parse
2016-05-06 11:24:12 +00:00
the file) but bad coding style and code smell. The HLint checker is called
*after* the flycheck GHC checker.
2016-05-02 22:16:13 +00:00
2020-07-30 16:13:49 +00:00
HLint can be configured via .hlint.yaml.
2016-05-06 11:24:12 +00:00
** Interactive haskell-mode
Finally, interactive haskell-mode (~SPC m s b~ ) also displays errors. These
2017-08-12 03:26:46 +00:00
errors can be navigated to, from the interactive buffer (by clicking on the
error) or using =haskell-goto-next-error= (~M-n~ ) and =haskell-goto-prev-error=
2016-05-06 11:24:12 +00:00
(~M-p~ ).
2016-05-02 22:16:13 +00:00
** Flymake
2017-08-12 03:26:46 +00:00
An alternative to syntax checking is to build your projects with
2019-05-26 20:58:52 +00:00
=flymake-compile= . It doesn't highlight errors in the buffer, but it's more
2016-05-06 11:24:12 +00:00
reliable. The error navigation is similar to interactive haskell-mode.
2016-08-01 07:04:27 +00:00
** Troubleshooting
2020-08-25 07:38:30 +00:00
Flycheck can fail silently for miscellaneous reasons. See the [[#faq ][FAQ ]]
2016-05-06 11:24:12 +00:00
for troubleshooting.
2015-10-07 16:59:57 +00:00
* FAQ
2016-05-06 11:24:12 +00:00
** The REPL doesn't work
2015-10-07 16:59:57 +00:00
Usually =haskell-mode= is great at figuring out which interactive process to
2017-08-12 03:26:46 +00:00
bring up. But if you are experiencing problems with it, then you can help
2015-10-07 16:59:57 +00:00
=haskell-mode= by setting =haskell-process-type= as in following code:
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
(setq-default dotspacemacs-configuration-layers
'((haskell :variables haskell-process-type 'stack-ghci)))
2015-10-07 16:59:57 +00:00
#+END_SRC
Available options are:
- ghci
- cabal-repl
2018-12-30 18:06:43 +00:00
- cabal-new-repl
2015-10-07 16:59:57 +00:00
- cabal-dev
- cabal-ghci
- stack-ghci
2016-05-06 11:24:12 +00:00
** The REPL is stuck
2019-05-26 20:58:52 +00:00
Make sure that there's a space between the REPL's =λ>= prompt and the cursor.
When there is no space, then the REPL will behave as if it's stuck. Usually,
2017-08-12 03:26:46 +00:00
when you enter normal state, the cursor moves backwards by one character, so there
is no required space when you switch to insert mode. There is a possible
workaround - just add the following snippet to your =dotspacemacs/user-config=
function:
2015-10-10 08:19:28 +00:00
#+BEGIN_SRC emacs-lisp
2020-01-27 11:20:53 +00:00
(when (configuration-layer/layer-used-p 'haskell)
2018-09-19 03:54:47 +00:00
(add-hook 'haskell-interactive-mode-hook
(lambda ()
(setq-local evil-move-cursor-back nil))))
2015-10-10 08:19:28 +00:00
#+END_SRC
2017-08-12 03:26:46 +00:00
It makes the cursor stay in the right place in the REPL buffer when you enter
2019-05-26 20:58:52 +00:00
normal state. Which in most cases helps you to avoid the problem with 'stuck'
2015-10-10 08:19:28 +00:00
REPL.
2017-08-12 03:26:46 +00:00
Also, some users might want to start the REPL in insert mode. This is done by
placing the following snippet in your =dotspacemacs/user-config= function:
2015-10-10 08:19:28 +00:00
#+BEGIN_SRC emacs-lisp
2020-01-27 11:20:53 +00:00
(when (configuration-layer/layer-used-p 'haskell)
2018-09-19 03:54:47 +00:00
(defadvice haskell-interactive-switch (after spacemacs/haskell-interactive-switch-advice activate)
(when (eq dotspacemacs-editing-style 'vim)
(call-interactively 'evil-insert))))
2015-10-10 08:19:28 +00:00
#+END_SRC
2016-05-06 11:24:12 +00:00
** Indentation doesn't reset when pressing return after an empty line
This is the intended behavior in =haskell-indentation-mode= . If you want to
2017-08-12 03:26:46 +00:00
reset the indentation when pressing return after an empty line, add the
following snippet into your =dotspacemacs/user-config= function.
2015-10-26 17:34:28 +00:00
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
(defun haskell-indentation-advice ()
(when (and (< 1 (line-number-at-pos))
(save-excursion
(forward-line -1)
(string= "" (s-trim (buffer-substring (line-beginning-position) (line-end-position))))))
(delete-region (line-beginning-position) (point))))
(advice-add 'haskell-indentation-newline-and-indent
:after 'haskell-indentation-advice)
2015-10-26 17:34:28 +00:00
#+END_SRC
2016-05-06 11:24:12 +00:00
2016-08-01 07:04:27 +00:00
** Flycheck displays HLint warnings but not errors
2017-08-12 03:26:46 +00:00
The HLint checker is called *after* the normal flycheck checker, even if the
2019-05-26 20:58:52 +00:00
checker fails. Check the [[#flycheck-doesnt-work ][Flycheck doesn't work ]] section.
2016-05-06 11:24:12 +00:00
2020-07-30 16:13:49 +00:00
** HLint fails with parse error
If HLint is not correctly configured (e.g. does not load some extensions that you are using in your project) it might fail while parsing the file.
Check [[https://github.com/ndmitchell/hlint ][HLint ]] docs for more details.
2016-05-06 11:24:12 +00:00
** I can see highlighted errors but they don't appear in the error list
The error list is only set by flycheck. You are probably seeing errors
2020-08-25 07:38:30 +00:00
highlighted by haskell-mode. Check the [[#flycheck-doesnt-work ][Flycheck doesn't work ]] section.
2016-05-06 11:24:12 +00:00
2016-05-02 22:16:13 +00:00
** Flycheck doesn't work
2019-05-26 20:58:52 +00:00
You can use the =flycheck-compile= command to check what's wrong with flycheck.
This will show you the exact command line that's used, and its output.
2016-05-02 22:16:13 +00:00
2019-05-26 20:58:52 +00:00
If you are using =stack= , check the [[#flycheck-doesnt-work-with-stack ][Flycheck doesn't work with =stack= ]] section.
2016-05-02 22:16:13 +00:00
** Flycheck doesn't work with =stack=
2017-08-12 03:26:46 +00:00
First check that flycheck uses the correct checker, and all the paths are
2016-05-06 11:24:12 +00:00
properly configured using =flycheck-verify-setup= (~SPC e v~ ). You can force the
2017-08-12 03:26:46 +00:00
checker with =flycheck-select-checker= (~SPC e s~ ) to ensure that it uses
2019-05-26 20:58:52 +00:00
=haskell-stack-ghc= . If it still doesn't work, then it could be one of the
2017-08-12 03:26:46 +00:00
following problems:
- The =stack= build directory is wrong
2016-05-06 11:24:12 +00:00
- The project root is not set properly
2017-08-12 03:26:46 +00:00
*** The =stack= build directory is wrong
The path to the build directory, which contains some generated files, is
normally under =.stack-work/install/<os>/Cabal-<version>/build= .
2016-05-06 11:24:12 +00:00
2019-05-26 20:58:52 +00:00
However the version of the cabal library that's used by =stack= to generate the
directory name is not the version of the cabal library that's installed by
=stack= but rather the version of cabal that's associated to the GHC version.
2017-08-12 03:26:46 +00:00
This error can happen after upgrading cabal or cabal-install. To check if this
2019-05-26 20:58:52 +00:00
is the problem, compare the path name of the build path that's used by flycheck
2017-08-12 03:26:46 +00:00
using =flycheck-compile= and compare it to the actual path in the =.stack-work=
2019-05-26 20:58:52 +00:00
directory. If they are different, then you'll need to reinstall ghc using the
2017-08-12 03:26:46 +00:00
command =stack setup --upgrade-cabal= .
2016-05-06 11:24:12 +00:00
*** The Project root directory is not set properly
2017-08-12 03:26:46 +00:00
Flycheck launches the GHC command, not from the project root directory, but from
2019-05-26 20:58:52 +00:00
the directory of the file that's being checked. This is normally not a problem,
2017-08-12 03:26:46 +00:00
as all the paths are set properly, however it could be a problem if some
template Haskell functions use relative paths (e.g. in Yesod scaffolded
projects).
2016-05-06 11:24:12 +00:00
2019-05-26 20:58:52 +00:00
Until it's fixed in flycheck, the workaround is to wrap the =stack= command in
order to run all subcommands from the project's root directory. You can do so
2017-08-12 03:26:46 +00:00
with the following script:
2016-05-02 22:16:13 +00:00
#+BEGIN_SRC bash
2018-09-19 03:54:47 +00:00
#!/bin/bash
2020-06-21 19:40:01 +00:00
cd `stack path --project-root`
2018-09-19 03:54:47 +00:00
stack $*
2016-05-02 22:16:13 +00:00
#+END_SRC
2016-05-06 11:24:12 +00:00
Make sure you set =flycheck-haskell-stack-ghc-executable= to this script.
2016-05-02 22:16:13 +00:00
2016-06-03 16:06:52 +00:00
** haskell-mode commands don't work
2017-08-12 03:26:46 +00:00
Some (most) of the haskell-mode commands only work when haskell-mode is in
interactive mode, i.e. has an interactive session associated with it. Load it
using ~SPC m s b~ .