IDE support when working on GHC

| tagged with

    Here are some notes for how I configure Neovim, haskell-language-server, and clangd for an IDE-like experience when working on GHC:

    • start using this an up-to-date ghc.nix

    • start a ghc.nix shell: nix-shell ../ghc.nix --arg withIde true

    • configure nvim-lspconfig’s HLS support to correctly identify the root directory of a GHC source tree:

          root_dir = function(fname)
              local util = lspconfig.util
              local x = util.root_pattern("hadrian")(fname)
              if x then
                  return x
              return util.root_pattern("*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml")(fname)
    • configure nvim-lspconfig use clangd:

    • create a compile_flags.txt for clangd (ideally this would be upstreamed as a .clangd file but this mechanism doesn’t appear to work):

    • Run haskell-language-server-wrapper compiler/GHC.hs to ensure that things work (and generate various things in .hie-bios)

    • Enjoy