如何告诉 HLS 使用 hls-class-plugin?

问题描述 投票:0回答:1

我正在寻找如何使用 HLS 发现 Haskell 文件中类型类的方法名称。

四处搜索,我发现此页面,其中提到了代码操作“添加缺少的类方法”。

我希望该功能在我的 IDE 中工作(我使用 Vim + YouCompleteMe),所以我刚刚通过

hls-class-plugin
¹ 安装了
cabal install hls-class-plugin
,成功了,但也以警告结束:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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.

问题是,我如何告诉 HLS 使用这个库?

我确实读到了

您可能希望将它们作为依赖项添加到您的包中。在这个 将“hls-class-plugin”添加到包的 build-depends 字段中 .cabal 文件。

但是哪个

.cabal
文件?毕竟我不希望这个功能在项目中可用...但每次我打开 Haskell 文件时都可用。


(1) 原则上我本以为应该通过

cabal install --lib hls-class-plugin
安装它,但结果却出错了:

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
haskell ide cabal haskell-language-server
1个回答
0
投票

必须使用设置的

haskell-language-server
标志来构建
class
包。然后
haskell-language-server
package
将使自己依赖于
hls-class-plugin
,链接到它,并在可执行文件运行时使用它。您不能告诉 HLS 使用任何不是在运行时构建的插件。

为了在

haskell-language-server
包上设置标志,您必须自己构建它。另外,如果默认情况下未设置标志(默认情况下未启用插件),这可能意味着该插件尚未更新到您为其构建 HLS 的 GHC 版本,因此无法保证您自己构建将工作。不管怎样,要从源代码构建
haskell-language-server
,我相信工作流程是这样的(已经有一段时间了,无论如何构建都非常挑剔)

  1. 将存储库克隆到某个目录并进入该目录。
  2. 查看标志(它们在
    .cabal
    文件中定义,但 Hackage 上的列表也可能也是最新的。
  3. 发出
    cabal configure -fflag1 -fflag2 ...
    以获得您想要的标志。您可能(可能?)需要设置
    -fignore-plugins-ghc-bounds
  4. 如果可能的话,
  5. cabal install
    应该构建包。可能不太可能吧!
  6. 上面的命令,如果它有效,会在某个地方放置一个
    haskell-language-server
    可执行文件...(该位置在你的 cabal 配置中配置,我认为它可以用
    --installdir
    设置)。
  7. 获取该可执行文件(它实际上可能是可执行文件的符号链接)并将其放在正确的位置,以便编辑器找到它。您可能应该在其名称中包含 GHC 版本,因为它特定于构建它的 GHC 版本。
© www.soinside.com 2019 - 2024. All rights reserved.