Enlico
Enlico

Reputation: 28490

How do I tell HLS to use hls-class-plugin?

I was looking for how to discover the names of the methods of a type class in a Haskell file using the HLS.

Searching around I found this page where the code action "Add missing class methods" is mentioned.

I would like that feature to work in my IDE (I use Vim + YouCompleteMe), so I've just installed hls-class-plugin via cabal install hls-class-plugin¹, which succeeded, but also ended with a warning:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: Installation might not be completed as desired! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The command "cabal install [TARGETS]" doesn't expose libraries.
* You might have wanted to add them as dependencies to your package. In this
case add "hls-class-plugin" to the build-depends field(s) of your package's
.cabal file.
* You might have wanted to add them to a GHC environment. In this case use
"cabal install --lib hls-class-plugin". The "--lib" flag is provisional: see
https://github.com/haskell/cabal/issues/6481 for more information.

The the question is, how do I tell the HLS to make use of this library?

I do read that

You might have wanted to add them as dependencies to your package. In this case add "hls-class-plugin" to the build-depends field(s) of your package's .cabal file.

but which .cabal file? After all I don't want this feature to be available in a project... but simply every time I open a Haskell file.


(¹) In principle I would have thought I should install it via cabal install --lib hls-class-plugin, but that just errored out:

Warning: The package list for 'hackage.haskell.org' is 70 days old.
Run 'cabal update' to get the latest list of available packages.
Warning: The package list for 'hackage.haskell.org' is 70 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Error: cabal: Cannot build the package hls-class-plugin because none of the
components are available to build: the library is marked as 'buildable:
False'; and the test suite 'tests' cannot be built because cabal does not
currently support building test suites or benchmarks of non-local dependencies

Upvotes: 0

Views: 134

Answers (1)

HTNW
HTNW

Reputation: 29193

The haskell-language-server package has to be built with the class flag set. Then haskell-language-server package will make itself depend on hls-class-plugin, link to it, and use it when the executable runs. You can't tell HLS to use any plugins it wasn't built with at runtime.

In order to set a flag on the haskell-language-server package, you have to build it yourself. Also, if a flag not set by default (a plugin is not enabled by default), that probably means that plugin hasn't been updated to the version of GHC you've built HLS for, so there's no guarantee a build you do yourself will work. Anyway, to build haskell-language-server from source, I believe the workflow is like this (it's been a while and the build's quite finicky anyway)

  1. Clone the repository into some directory and enter that directory.
  2. Take a look at the flags (they're defined in .cabal file, but the list on Hackage is probably also up-to-date.
  3. Issue cabal configure -fflag1 -fflag2 ... for the flags you want. You may (probably?) need to set -fignore-plugins-ghc-bounds.
  4. cabal install should build the package, if possible. It might not be possible!
  5. The above command, if it works, puts a haskell-language-server executable... somewhere (the location is configured in your cabal config, and I think it can be set with --installdir).
  6. Take that executable (it'll actually probably be a symlink to the executable) and put it in the right place for your editor to find it. You should probably include the GHC version in its name as it is specific to the GHC version it was built with.

Upvotes: 0

Related Questions