Haskell Language Server and Coc

Haskell has great IDE support via Haskell Language Server or HLS.

Coc.nvim is the recommended extension to get Language Server Protocol (LSP) support for editing Haskell in neovim.

It turns out that home-manager has a module that, unlike the NixOS version, provides a declarative way to install and configure coc.nvim with Haskell support (EDIT: this is language-independent):

{
  programs.neovim = {
    coc = {
      enable = true;
      settings = {
        languageserver = {
          haskell = {
            command = "haskell-language-server-wrapper";
            args = [ "--lsp" ];
            rootPatterns = [
              "*.cabal"
              "cabal.project"
              "hie.yaml"
            ];
            filetypes = [ "haskell" "lhaskell" ];
          };
        };
      };
    };
  };
}

https://github.com/srid/nixos-config/commit/9a6410331063ae97ae405837559cf4c5b3990ada

It does work when trying out in the nix-shell of haskell-template.

Declarative plugin config in Nix

The above is neatβ€”no need to hand-write VimScript or Lua just to configure the extension. Can we do the same for other neovim extensions in Nix? A couple of attempts exist: nix-neovim and NixVim.

Links to this page
  • Modular neovim plugin configuration

    In the previous post I hinted about configuring neovim plugins declaratively in Nix. Today, I discovered that this is indeed possible,* in some basic form, in home-manager.

    It is not really declarative, though β€” more like modular. Declarative would be how Coc is configured in home-manager; see Haskell Language Server and Coc. Nevertheless, it is nice to be able to both configure and enable a plugin in the same place. Give the large number of neovim plugins in nixpkgs, it is not realistic to expect all of them to support declarative config anyway.

#neovim #haskell