Haskell 语言服务器尝试使用不正确的 GHC 版本

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

我正在尝试在 Spacemacs 中使用 Haskell 语言服务器。我使用 ghcup 安装了 HLS。我的操作系统是Ubuntu 20.04.5。在 Spacemacs 中打开 hs 文件时,我收到以下错误消息:

No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.5.0.0 x86_64 ghc-9.2.8
Current directory: ~/Documents/Code/hs-nexus-parser
Operating system: linux
Arguments: ["--lsp","-d","-l","/tmp/hls.log"]
Cradle directory: ~/Documents/Code/hs-nexus-parser
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.10.2.1
stack:          2.13.1
ghc:            8.6.5


Consulting the cradle to get project GHC version...
2024-02-02T15:20:42.278912Z | Debug | executing command: stack setup --silent
2024-02-02T15:20:42.574191Z | Debug | executing command: stack exec ghc -- --numeric-version
Project GHC version: 9.6.4
haskell-language-server exe candidates: ["haskell-language-server-9.6.4","haskell-language-server"]
Failed to find a HLS version for GHC 9.6.4
Executable names we failed to find: haskell-language-server-9.6.4,haskell-language-server
 2024-02-02T15:20:42.927797Z | Info | Starting server
2024-02-02T15:20:42.929304Z | Error | Got error while decoding initialize:
Error in $.params.capabilities.window.showMessage: parsing ShowMessageRequestClientCapabilities failed, expected Object, but encountered Null

Process lsp-haskell stderr finished

在我看来,有几个问题同时发生。

首先,HLS 似乎在 $PATH 中找到了错误的 GHC 版本。我确保预先添加

~/.ghcup/bin
到路径。该目录中的 ghc 版本是 9.4.8,它应该与我安装的 hls 版本一起使用。我还检查了 PATH 中的目录,但找不到 ghc 8.6.5 版本。当我在终端中运行
ghc --version
时,它给出版本 9.4.8。

其次,当它发现的 GHC 版本与 HLS 不匹配时,似乎会回退到本地堆栈项目中的 GHC 版本。为了防止这种情况,我将

system-ghc: true
添加到本地 stack.yaml 文件中,但这似乎没有帮助。

据我了解,Stack 应该与 ghcup 集成,因为我使用标准设置将其与 ghcup 一起安装。为了确保这有效,我通过删除 ~/.stack 卸载了以前的堆栈版本。

预期行为:HLS 使用一些与其兼容的 GHC 来完成代码。

haskell haskell-stack language-server-protocol spacemacs ghcup
1个回答
0
投票

我在自定义 Emacs 设置时基本上遇到了这个问题。我去查看

~/.ghcup/bin
,但我没有任何
haskell-language-server-9.6.4
haskell-language-server
,所以我的解决办法就是安装
hls 2.6.0.0
,尽管它目前是
latest
而不是
recommended

我跑了:

$ ghcup install hls 2.6.0.0

Emacs 的工作非常有魅力。无需将其设置为默认值或其他任何内容。

我觉得有些东西仍然很奇怪,因为

hls
忽略了配置文件并寻找
ghc 9.6.4
,所以我得到的答案并不完全令人满意,但这让LSP运行得足够好以满足我的目的。希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.