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
The
haskell-language-serverpackage has to be built with theclassflag set. Thenhaskell-language-serverpackage will make itself depend onhls-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-serverpackage, 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 buildhaskell-language-serverfrom source, I believe the workflow is like this (it's been a while and the build's quite finicky anyway).cabalfile, but the list on Hackage is probably also up-to-date.cabal configure -fflag1 -fflag2 ...for the flags you want. You may (probably?) need to set-fignore-plugins-ghc-bounds.cabal installshould build the package, if possible. It might not be possible!haskell-language-serverexecutable... somewhere (the location is configured in your cabal config, and I think it can be set with--installdir).