Skip to content

Provide haskell-language-server-wrapper to help direnv #1776

@peterbecich

Description

@peterbecich

Is your feature request related to a problem? Please describe.

I am using a haskell.nix Flake, Haskell Language Server, direnv, Emacs, and envrc for Emacs.

I am trying to make the haskell.nix Flake provide HLS to Emacs. I don't want Emacs to use /home/peterbecich/.ghcup/bin/haskell-language-server-9.2.4.

lsp-haskell for Emacs launches HLS. By default it looks for haskell-language-server-wrapper; not haskell-language-server, haskell-language-server-9.2.4, etc. :
https://github.com/emacs-lsp/lsp-haskell/blob/485c1148ce4d27030bb95b21c7289809294e7d31/lsp-haskell.el#L220-L225

Here is an example project which uses a haskell.nix Flake to provide Haskell Language Server in the nix develop shell: https://github.com/peterbecich/halogen-chess
and the relevant configuration for that:

          devShells.default = pkgs.hixProject.shellFor {
            tools =
              { cabal = "latest";
                hlint = "latest";
                haskell-language-server = "latest";
              };
           ...

https://github.com/peterbecich/halogen-chess/blob/7b295327f9503fe7db09b6f7c2bbc50539c601a5/flake.nix#L195-L200

If I open nix develop and look for HLS, here is the binary provided by haskell.nix:

$ which haskell-language-server 
/nix/store/50l8pg2qmi4g3mlp9xbjhxgd1i6hkgp0-haskell-language-server-exe-haskell-language-server-1.8.0.0/bin/haskell-language-server

Here is the binary haskell-language-server-wrapper which will be found by lsp-haskell:

$ which haskell-language-server-wrapper 
/home/peterbecich/.ghcup/bin/haskell-language-server-wrapper

The critical error is that haskell-language-server-wrapper then fails to point back to the Nix HLS binary; instead it points to /home/peterbecich/.ghcup/bin/haskell-language-server-9.2.4.

$ haskell-language-server-wrapper --example 
....
haskell-language-server exe candidates: ["haskell-language-server-9.2.4","haskell-language-server"]
Launching haskell-language-server exe at:/home/peterbecich/.ghcup/bin/haskell-language-server-9.2.4
GHC ABIs don't match!
...

Looking at the HLS code, if these two strings in candidates' were reversed, perhaps it would work correctly, I'm not sure:

        hlsBin = "haskell-language-server-" ++ ghcVersion
        candidates' = [hlsBin, "haskell-language-server"]
        candidates = map (++ exeExtension) candidates'

https://github.com/haskell/haskell-language-server/blob/85f788135175a007d3db4ac911c4115b30ab9d87/exe/Wrapper.hs#L150-L153

Describe the solution you'd like

When haskell.nix is configured to provide haskell-language-server in the nix develop shell, it should also provide the haskell-language-server-wrapper binary. The result would be something like:

$ which haskell-language-server 
/nix/store/12345-haskell-language-server-exe-haskell-language-server-1.8.0.0/bin/haskell-language-server

$ which haskell-language-server-wrapper 
/nix/store/12345-haskell-language-server-exe-haskell-language-server-wrapper-1.8.0.0/bin/haskell-language-server-wrapper

I am assuming the Nix haskell-language-server-wrapper would then point to the Nix haskell-language-server.

Describe alternatives you've considered
lsp-haskell has a configuration option to point to a different HLS binary:

 '(lsp-haskell-server-path "haskell-language-server")

This actually fixes the issue. My preference is this would be solved in haskell.nix and not in the LSP clients for Emacs and other editors.

Thank you!

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions