mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2026-05-11 08:28:04 +02:00
languages/haskell: haskell-tools setupOpts refactor
This commit is contained in:
parent
b2d6a252ce
commit
29d37d9692
1 changed files with 59 additions and 52 deletions
|
|
@ -4,17 +4,15 @@
|
|||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) attrNames isList;
|
||||
inherit (builtins) attrNames;
|
||||
inherit (lib) genAttrs;
|
||||
inherit (lib.types) either package enum listOf str;
|
||||
inherit (lib.types) either package enum listOf str nullOr;
|
||||
inherit (lib.options) mkEnableOption mkOption literalExpression;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
inherit (lib.nvim.dag) entryAfter;
|
||||
inherit (lib.nvim.types) mkGrammarOption deprecatedSingleOrListOf mkPluginSetupOption luaInline;
|
||||
inherit (lib.nvim.attrsets) mapListToAttrs;
|
||||
inherit (lib.meta) getExe getExe';
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (pkgs) haskellPackages;
|
||||
|
||||
cfg = config.vim.languages.haskell;
|
||||
|
|
@ -88,6 +86,59 @@ in {
|
|||
extensions = {
|
||||
haskell-tools = {
|
||||
enable = mkEnableOption "haskell-tools.nvim";
|
||||
|
||||
setupOpts = mkPluginSetupOption "haskell-tools.nvim" {
|
||||
hls = {
|
||||
cmd = mkOption {
|
||||
type = nullOr (listOf str);
|
||||
default = [
|
||||
"${pkgs.haskellPackages.haskell-language-server}/bin/haskell-language-server"
|
||||
"--lsp"
|
||||
];
|
||||
description = ''
|
||||
Command for haskell-language-server.
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> Since HLS is very sensitive about the GHC version, there's a
|
||||
> very high chance that the default HLS we use is not
|
||||
> compatible with your project. It is highly recommended to set
|
||||
> this option to `null` and install HLS separately in a
|
||||
> `devShell`.
|
||||
'';
|
||||
};
|
||||
on_attach = mkOption {
|
||||
type = nullOr luaInline;
|
||||
description = "Function to run when HLS is attached";
|
||||
default = mkLuaInline ''
|
||||
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
dap = {
|
||||
cmd = mkOption {
|
||||
type = nullOr (listOf str);
|
||||
default = null;
|
||||
description = "Debug adapter command";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -152,51 +203,7 @@ in {
|
|||
vim = {
|
||||
extraPackages = [haskellPackages.cabal-fmt];
|
||||
startPlugins = ["haskell-tools-nvim"];
|
||||
luaConfigRC.haskell-tools-nvim = entryAfter ["lsp-servers"] ''
|
||||
vim.g.haskell_tools = {
|
||||
tools = {
|
||||
hover = {
|
||||
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 = {
|
||||
haskell = {
|
||||
formattingProvider = "none",
|
||||
cabalFormattingProvider = "cabal-fmt",
|
||||
},
|
||||
},
|
||||
},
|
||||
${optionalString cfg.dap.enable ''
|
||||
dap = {
|
||||
cmd = ${
|
||||
if isList cfg.dap.package
|
||||
then toLuaObject cfg.dap.package
|
||||
else ''{"${cfg.dap.package}/bin/haskell-debug-adapter"}''
|
||||
},
|
||||
},
|
||||
''}
|
||||
}
|
||||
'';
|
||||
globals.haskell_tools = cfg.extensions.haskell-tools.setupOpts;
|
||||
};
|
||||
})
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue