plugins/languages: add haskell support

This commit is contained in:
Artur Manuel 2024-12-15 23:30:58 +00:00
parent a0a57757a0
commit f311be9a2d
5 changed files with 123 additions and 0 deletions

View file

@ -55,6 +55,7 @@ isMaximal: {
sql.enable = isMaximal;
java.enable = isMaximal;
kotlin.enable = isMaximal;
haskell.enable = isMaximal;
ts.enable = isMaximal;
go.enable = isMaximal;
lua.enable = isMaximal;

View file

@ -684,6 +684,22 @@
"type": "github"
}
},
"plugin-haskell-tools-nvim": {
"flake": false,
"locked": {
"lastModified": 1734222260,
"narHash": "sha256-gZVN9ADPO5wFOaf19FydCneb7aKTT9K1vcLoBURPEjk=",
"owner": "mrcjkb",
"repo": "haskell-tools.nvim",
"rev": "943b77b68a79d3991523ba4d373063c9355c6f55",
"type": "github"
},
"original": {
"owner": "mrcjkb",
"repo": "haskell-tools.nvim",
"type": "github"
}
},
"plugin-highlight-undo": {
"flake": false,
"locked": {
@ -2091,6 +2107,7 @@
"plugin-gitsigns-nvim": "plugin-gitsigns-nvim",
"plugin-glow-nvim": "plugin-glow-nvim",
"plugin-gruvbox": "plugin-gruvbox",
"plugin-haskell-tools-nvim": "plugin-haskell-tools-nvim",
"plugin-highlight-undo": "plugin-highlight-undo",
"plugin-hop-nvim": "plugin-hop-nvim",
"plugin-icon-picker-nvim": "plugin-icon-picker-nvim",

View file

@ -720,5 +720,10 @@
url = "github:otavioschwanck/new-file-template.nvim";
flake = false;
};
plugin-haskell-tools-nvim = {
url = "github:mrcjkb/haskell-tools.nvim";
flake = false;
};
};
}

View file

@ -14,6 +14,7 @@ in {
./hcl.nix
./kotlin.nix
./html.nix
./haskell.nix
./java.nix
./lua.nix
./markdown.nix

View file

@ -0,0 +1,99 @@
{
config,
lib,
pkgs,
...
}: let
inherit (builtins) isList;
inherit (lib) options modules nvim strings types;
inherit (types) either package listOf str;
inherit (options) mkEnableOption mkOption;
inherit (strings) optionalString;
inherit (modules) mkIf mkMerge;
inherit (nvim.types) mkGrammarOption;
inherit (nvim.dag) entryAnywhere;
inherit (nvim.lua) expToLua;
inherit (pkgs) haskellPackages;
cfg = config.vim.languages.haskell;
in {
options.vim.languages.haskell = {
enable = mkEnableOption "Haskell support";
treesitter = {
enable = mkEnableOption "Treesitter support for Haskell" // {default = config.vim.languages.enableTreesitter;};
package = mkGrammarOption pkgs "haskell";
};
lsp = {
enable = mkEnableOption "LSP support for Haskell" // {default = config.vim.languages.enableLSP;};
package = mkOption {
description = "Haskell LSP package or command to run the Haskell LSP";
default = haskellPackages.haskell-language-server;
type = either package (listOf str);
};
};
dap = {
enable = mkEnableOption "DAP support for Haskell" // {default = config.vim.languages.enableDAP;};
package = mkOption {
description = "Haskell DAP package or command to run the Haskell DAP";
default = haskellPackages.haskell-debug-adapter;
type = either package (listOf str);
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter = {
enable = true;
grammars = [cfg.treesitter.package];
};
})
(mkIf (cfg.dap.enable || cfg.lsp.enable) {
vim = {
startPlugins = ["haskell-tools-nvim"];
luaConfigRC.haskell-tools-nvim =
entryAnywhere
''
vim.g.haskell_tools = {
${optionalString cfg.lsp.enable ''
-- LSP
tools = {
hover = {
enable = true,
},
},
hls = {
cmd = ${
if isList cfg.lsp.package
then expToLua cfg.lsp.package
else ''{"${cfg.lsp.package}/bin/haskell-language-server-wrapper"}''
},
on_attach = function(client, bufnr, ht)
default_on_attach(client, bufnr, ht)
local opts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', '<space>cl', vim.lsp.codelens.run, opts)
vim.keymap.set('n', '<space>hs', ht.hoogle.hoogle_signature, opts)
vim.keymap.set('n', '<space>ea', ht.lsp.buf_eval_all, opts)
vim.keymap.set('n', '<leader>rr', ht.repl.toggle, opts)
vim.keymap.set('n', '<leader>rf', function()
ht.repl.toggle(vim.api.nvim_buf_get_name(0))
end, opts)
vim.keymap.set('n', '<leader>rq', ht.repl.quit, opts)
end,
},
''}
${optionalString cfg.dap.enable ''
dap = {
cmd = ${
if isList cfg.dap.package
then expToLua cfg.dap.package
else ''${cfg.dap.package}/bin/haskell-debug-adapter''
},
},
''}
}
'';
};
})
]);
}