mrcjkb / haskell-tools.nvim

🦥 Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
460 stars 17 forks source link

Allow setting hls `cmd` per project #200

Closed mrcjkb closed 7 months ago

mrcjkb commented 1 year ago

Feature description

This would be useful e.g. to set cmd = cabal run haskell-language-server -- --lsp in the hls project.

glyh commented 1 year ago

It should also be good if this plugin can detect the haskell-language-server version we should use. I have haskell-language-server in my path but it's complaining that the version of ghcide doesn't match my package.

I search here and got https://www.reddit.com/r/haskell/comments/i8rfx0/ghcide_compiled_against_ghc_865_but_currently/

But I have no clue how to fix the issue.

mrcjkb commented 1 year ago

@glyh, thanks for the suggestion.

haskell-language-server needs to be compiled with the same version of ghc that you're using to compile your project.

Detecting which version to use would fall into the category of package management, which is outside the scope of this plugin. If you're looking for something like this, there are various different approaches you can choose from:

glyh commented 1 year ago

Hello, I'm using ghcup with stack 2.9.3, hls 2.0.0.1, ghc 9.2.8 and cabal 3.6.2. But I am still getting the errors. If I remember correctly mason hls is broken, arch's haskell packages are broken as well and that's the very reason I'm using ghcup.

I don't want to use nix shell because it takes too much time to configure.

mrcjkb commented 1 year ago

If you're using ghcup with stack, you may need to configure stack to use the ghc binaries managed by ghcup.

See also vscode-haskell#ghc-abis-dont-match.

As installing haskell-language-server is beyond the scope of this plugin, I suggest you ask on IRC, in the haskell tooling matrix channel, or open an issue in the haskell-language-server repository if you're still facing issues.

Arch's static Haskell packages (in the AUR) don't seem to be broken. But they may have the same issue with stack.

anuramat commented 7 months ago

ghcup on NixOS is a PITA: the package is broken for half a year, and binaries from the website have a dynamic loader, so in my opinion this option could be pretty useful (the executable override)

mrcjkb commented 7 months ago

This has been supported for a while - I just forgot about the issue :smile:

With the current version of this plugin, there are multiple ways you can dynamically set the cmd:

  1. Using :h exrc: If enabled, you can set vim.g.haskell_tools in .nvim.lua, .nvimrc, or .exrc files in the project root.
  2. Since version 2.4.0, vim.g.haskell_tools can also be a function. So you can use that to determine the project you're in and return a value accordingly.
  3. vim.g.haskell_tools.hls.cmd can also be either a list of strings or a function that returns a list of strings.

The first two methods won't work if you load multiple projects with the same Neovim session, as vim.g.haskell_tools is sourced into an internal config only once, when opening a Haskell file.

If hls.cmd is a function, it is evaluated every time the LSP client starts, so this method can be used with multiple projects in the same session.

mrcjkb commented 7 months ago

ghcup on NixOS is a PITA: the package is broken for half a year, and binaries from the website have a dynamic loader, so in my opinion this option could be pretty useful (the executable override)

If you only need to override the cmd, that has always been supported. See :h haskell-tools.config and :h HaskellLspClientOpts.

anuramat commented 7 months ago

damn, how did I miss that I swear I Read TFM thanks for the help 🙇‍♂️