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:

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

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

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

    • Enjoy