languages/haskell.nix: fix invalid keys in the haskell-tools configuration

These keys presented the error `unrecognized configs in
vim.g.haskell_tools: { "hls.filetypes", "hls.root_dir",
"tools.hover.enable", "hls.enable" }` on attaching to any haskell file.
This commit is contained in:
dathegreat 2026-04-24 12:52:08 -06:00 committed by Ching Pei Yang
commit 171a5bf656
2 changed files with 65 additions and 29 deletions

View file

@ -201,6 +201,13 @@
- Updated nix language plugin to use pkgs.nixfmt instead of - Updated nix language plugin to use pkgs.nixfmt instead of
pkgs.nixfmt-rfc-style pkgs.nixfmt-rfc-style
[dathegreat](https://github.com/dathegreat):
- Fixed invalid keys in the haskell-tools configuration
- Changed the default haskell formatter to
[fourmolu](https://github.com/fourmolu/fourmolu), matching the
[haskell-tools default](https://github.com/mrcjkb/haskell-tools.nvim/blob/9ea030aa67f3875753e70e1eb59701f7020479a0/lua/haskell-tools/config/internal.lua#L131)
[alfarel](https://github.com/alfarelcynthesis): [alfarel](https://github.com/alfarelcynthesis):
[obsidian.nvim]: https://github.com/obsidian-nvim/obsidian.nvim [obsidian.nvim]: https://github.com/obsidian-nvim/obsidian.nvim

View file

@ -4,14 +4,19 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (builtins) isList attrNames; inherit (builtins) attrNames;
inherit (lib.types) either package enum listOf str; inherit
(lib.types)
either
package
enum
listOf
str
;
inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.options) mkEnableOption mkOption literalExpression;
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.dag) entryAfter;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.meta) getExe'; inherit (lib.meta) getExe';
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (pkgs) haskellPackages; inherit (pkgs) haskellPackages;
@ -22,8 +27,14 @@
servers = { servers = {
hls = { hls = {
enable = false; enable = false;
cmd = [(getExe' pkgs.haskellPackages.haskell-language-server "haskell-language-server-wrapper") "--lsp"]; cmd = [
filetypes = ["haskell" "lhaskell"]; (getExe' pkgs.haskellPackages.haskell-language-server "haskell-language-server-wrapper")
"--lsp"
];
filetypes = [
"haskell"
"lhaskell"
];
on_attach = on_attach =
mkLuaInline mkLuaInline
/* /*
@ -116,29 +127,47 @@ in {
(mkIf (cfg.dap.enable || cfg.lsp.enable) { (mkIf (cfg.dap.enable || cfg.lsp.enable) {
vim = { vim = {
startPlugins = ["haskell-tools-nvim"]; startPlugins = ["haskell-tools-nvim"];
luaConfigRC.haskell-tools-nvim = luaConfigRC.haskell-tools-nvim = entryAfter ["lsp-servers"] ''
entryAfter
["lsp-servers"]
''
vim.g.haskell_tools = { vim.g.haskell_tools = {
${optionalString cfg.lsp.enable ''
-- LSP
tools = { tools = {
hover = { hover = {
enable = true, stylize_markdown = false,
auto_focus = false,
},
},
hls = {
auto_attach = true,
cmd = {"${getExe' haskellPackages.haskell-language-server "haskell-language-server-wrapper"}", "--lsp"},
on_attach = function(client, bufnr)
local ht = require("haskell-tools")
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', '<localleader>cl', vim.lsp.codelens.run, opts)
vim.keymap.set('n', '<localleader>hs', ht.hoogle.hoogle_signature, opts)
vim.keymap.set('n', '<localleader>ea', ht.lsp.buf_eval_all, opts)
vim.keymap.set('n', '<localleader>rr', function()
vim.cmd('Haskell repl toggle')
end, opts)
vim.keymap.set('n', '<localleader>rf', function()
vim.cmd('Haskell repl toggle ' .. vim.api.nvim_buf_get_name(0))
end, opts)
vim.keymap.set('n', '<localleader>rq', function()
vim.cmd('Haskell repl quit')
end, opts)
end,
settings = function(project_root)
local ht = require("haskell-tools")
return ht.lsp.load_hls_settings(project_root)
end,
default_settings = {
haskell = {
formattingProvider = "fourmolu",
cabalFormattingProvider = "cabal-fmt",
},
}, },
}, },
hls = ${toLuaObject servers.hls},
''}
${optionalString cfg.dap.enable ''
dap = { dap = {
cmd = ${ cmd = {"${getExe' haskellPackages.haskell-debug-adapter "haskell-debug-adapter"}"},
if isList cfg.dap.package
then toLuaObject cfg.dap.package
else ''{"${cfg.dap.package}/bin/haskell-debug-adapter"}''
}, },
},
''}
} }
''; '';
}; };