Skip to content

Spacemacs layer for using a nix friendly haskell-ide-engine lsp

License

Notifications You must be signed in to change notification settings

sydneyhaskell/spacemacs-hie-nix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hie-nix Layer

Table of Contents

Description

This layer adds a hie + lsp setup that wraps commands up in nix-shell for the project. This is shamelessly copied from the existing haskell layer and culling all of the variability around dante/intero/etc. It will not work for you if you do not build your haskell projects with nix. There are simpler instructions in the hie wiki that will work better for that right now.

I don’t really know all the layers that well at the moment, so starting with the simplest thing that worked seemed like the best idea. It can get fancier later and layer the modes if that is better and I understand how it all interacts. This would not have happened so easily without Sam Evan-Powell’s awesome gist.

One thing that could be annoying for you is the lack of company support with dante. If that annoys you, you should probably extend the haskell layer with dante and set your completion backend to dante.

PRs and feedback are very welcome if you find this useful but lacking in some way.

Features:

  • syntax highlighting for haskell source, cabal files, C– source,
  • lsp-mode & lsp-ui powered by lsp-haskell and haskell-ide-engine

    Expect this layer to have some teething issues! Alan himself says this of haskell-lsp: ”This package is still under development, and is not recommended for daily use”. I still use it for my daily haskell, but expect bugs and needing to help out to make it nice. This layer is my first step toward this! :)

Install

Layer

To use this configuration layer, first clone it into ~/.emacs.d/private with the following command:

cd ~/.emacs.d/private/
git clone git@github.com:benkolera/spacemacs-hie-nix.git hie-nix

and add the layer to your ~/.spacemacs. You will need to add hie-nix to the existing dotspacemacs-configuration-layers list in this file.

Dependencies

You should also install the required haskell-ide-engine and tools via nix.

Binary Cache

First, you should make sure https://hie-nix.cachix.org is in your binary cache list otherwise you will wait a really long time for it to build! :)

Nixos

If you are using nixos, add “https://hie-nix.cachix.org” to nix.binaryCaches and “hie-nix.cachix.org-1:EjBSHzF6VmDnzqlldGXbi0RM3HdjfTU3yDRi9Pd0jTY=” to nix.binaryCachePublicKeys.

Non-Nixos

Installing the cachix binary and following the instructions at https://hie-nix.cachix.org ought to work.

Nix Env Install

Run this to install all of the dependencies into your user nix environment. If the cache is setup properly, you should see some things being downloaded from https://hie-nix.cachix.org and it should be pretty quick. If it starts building and takes hours, go back a step or ask me for help. I’m usually available on the freenode IRC in #qfpl.

cd ~/.emacs.d/private
nix-env -f default.nix -iA hie-spacemacs-bundle

Key bindings

All Haskell specific bindings are prefixed with the major-mode leader SPC m.

Top-level commands are prefixed by SPC m:

Key BindingDescription
SPC m g ggo to definition or tag
SPC m g icycle the Haskell import lines or return to point (with prefix arg)
SPC m Fformat buffer using haskell-stylish

Documentation

Documentation commands are prefixed by SPC m h

Key BindingDescription
SPC m h dfind or generate Haddock documentation for the identifier under the cursor
SPC m h fdo a helm-hoogle lookup
SPC m h hdo a Hoogle lookup
SPC m h Hdo a local Hoogle lookup
SPC m h igets information for the identifier under the cursor
SPC m h tgets the type of the identifier under the cursor
SPC m h ydo a Hayoo lookup

Debug

Debug commands are prefixed by SPC m d:

Key BindingDescription
SPC m d aabandon current process
SPC m d binsert breakpoint at function
SPC m d Bdelete breakpoint
SPC m d ccontinue current process
SPC m d dstart debug process, needs to be run first
SPC m d nnext breakpoint
SPC m d Nprevious breakpoint
SPC m d pprevious breakpoint
SPC m d rrefresh process buffer
SPC m d sstep into the next function
SPC m d ttrace the expression

Debug Buffer

Key BindingDescription
RETselect object at the point
aabandon current computation
bbreak on function
ccontinue the current computation
ddelete object at the point
istep into the next function
rrefresh the debugger buffer
sgo to next step to inspect bindings
Sgo to previous step to inspect the bindings
ttrace the expression

REPL

REPL commands are prefixed by SPC m s:

Key BindingDescription
SPC m s bload or reload the current buffer into the REPL
SPC m s cclear the REPL
SPC m s sshow the REPL without switching to it
SPC m s Sshow and switch to the REPL

Cabal commands

Cabal commands are prefixed by SPC m c:

Key BindingDescription
SPC m c acabal actions
SPC m c bbuild the current cabal project, i.e. invoke cabal build
SPC m c ccompile the current project, i.e. invoke ghc
SPC m c vvisit the cabal file

Cabal files

These commands are available in a cabal file.

Key BindingDescription
SPC m dadd a dependency to the project
SPC m bgo to benchmark section
SPC m ego to executable section
SPC m tgo to test-suite section
SPC m mgo to exposed modules
SPC m lgo to library section
SPC m ngo to next subsection
SPC m pgo to previous subsection
SPC m s cclear the REPL
SPC m s sshow the REPL without switching to it
SPC m s Sshow and switch to the REPL
SPC m Ngo to next section
SPC m Pgo to previous section
SPC m ffind or create source-file under the cursor

Refactor

Refactor commands are prefixed by SPC m r:

Key BindingDescription
SPC m r RRename using the lsp server
SPC m r freformat the buffer via the lsp server
SPC m r aapply sideline code action via lsp

FAQ

Get an error from cabal helper when hie starts

That normally means that you don’t have the cabal (library) version that hie needs to read in the project data. Add it by overriding your tool deps in your shell.nix using pkgs.haskell.lib.addBuildTool to an appropriate haskellPackages.Cabal_2_4_0_1 like value. The version that you need will be in the cabal helper error output, which should be in the hie-stderr emacs buffer.

Can’t find testing or benchmark dependencies

HIE still relies on the old-school cabal configure, so if you use the new-style stuff you will need to `cabal configure –enable-tests` etc to get the testing deps in there. If you have never done this in the project, hie will just run a `cabal configure` for you and miss the extra stuff.

Known Issues

Hoogle Support

Even if you have a nix ghc environment that creates a hoogle database, hie cannot find this database, presumably because it is accessing hoogle via the haskell API rather than the wrapped hoogle binary that is in the environment (which has a DB location hardcoded into it).

About

Spacemacs layer for using a nix friendly haskell-ide-engine lsp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 86.8%
  • Nix 11.6%
  • Shell 1.6%