mrcjkb/haskell-tools.nvim插件安装运行故障求助
Haskell-tools.nvim 插件适配问题排查与解决
问题背景
- 本地Haskell及ghci运行正常,但使用mrcjkb/haskell-tools.nvim插件时,严格遵循文档操作、复制可用配置、从零重装均无效
- 初始错误:打开.hs文件或执行
checkhealth命令时,抛出attempt to call field 'joinpath' (a nil value) - 更新Neovim、重装ghcup、HLS后,错误变更为:无法找到适配GHC 9.4.7的HLS版本,已下载对应GHC版本并配置仍未解决
初始错误日志
Error detected while processing BufReadPost Autocommands for "*": Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufReadPost Autocommands for "*"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[19]..script /home/draell/.local/share/nvim/lazy/haskell-tools.nvim/ftplugin/haskell.lua: Vim(runtime):E5113: Error while calling lua chunk: ...haskell-tools.nvim/lua/haskell-tools/config/internal.lua:115: attempt to call field 'joinpath' (a nil value) stack traceback: ...haskell-tools.nvim/lua/haskell-tools/config/internal.lua:115: in main chunk [C]: in function 'require' ...m/lazy/haskell-tools.nvim/lua/haskell-tools/internal.lua:11: in main chunk [C]: in function 'require' .../share/nvim/lazy/haskell-tools.nvim/ftplugin/haskell.lua:1: in main chunk [C]: in function 'nvim_cmd' /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24> [C]: in function 'nvim_buf_call' /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10> stack traceback: [C]: in function 'nvim_cmd' /usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24> [C]: in function 'nvim_buf_call' /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10> stack traceback: [C]: in function 'nvim_buf_call' /usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
更新后错误日志
无法找到适配GHC 9.4.7的HLS版本 未找到的可执行文件名:haskell-language-server-9.4.7,haskell-language-server:
排查与解决步骤
针对初始joinpath错误
joinpath是Neovim 0.8+新增的API,执行nvim --version确认版本是否≥0.8,低于该版本需升级到稳定版或最新版- 若已升级仍报错,执行
:Lazy update haskell-tools.nvim(基于Lazy.nvim)将插件更新至最新版
针对HLS版本适配问题
- 确认对应版本HLS已安装
- 执行
ghcup list查看已安装的HLS版本,需存在适配GHC 9.4.7的版本(通常HLS大版本与GHC匹配,如HLS 1.10.x适配GHC 9.4) - 未安装则执行
ghcup install hls --ghc 9.4.7指定GHC版本安装对应HLS
- 执行
- 检查HLS路径是否在系统PATH中
- 执行
which haskell-language-server或which haskell-language-server-9.4.7确认可执行文件路径 - 若不在PATH,将
~/.ghcup/bin添加到环境变量(如在~/.bashrc或~/.zshrc中添加export PATH="$HOME/.ghcup/bin:$PATH")
- 执行
- 手动指定HLS路径到插件配置
在haskell-tools.nvim的配置中添加HLS绝对路径:require('haskell-tools').setup { hls = { cmd = { '/home/你的用户名/.ghcup/bin/haskell-language-server-9.4.7' }, }, } - 确认项目GHC版本匹配
检查项目根目录的cabal.project或stack.yaml,确保指定的GHC版本为9.4.7,避免项目使用其他版本导致HLS不兼容
内容的提问来源于stack exchange,提问作者JJoaoll
相关产品推荐
相关产品推荐

