diff --git a/modules/plugins/languages/haskell.nix b/modules/plugins/languages/haskell.nix index 5a5cb142..f50c9f09 100644 --- a/modules/plugins/languages/haskell.nix +++ b/modules/plugins/languages/haskell.nix @@ -9,80 +9,12 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.strings) optionalString; inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.types) mkGrammarOption enum attrNames; + inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.dag) entryAfter; inherit (lib.nvim.lua) expToLua; - inherit (lib.meta) getExe; - inherit (lib.generators) mkLuaInline; - inherit (lib.nvim.attrsets) mapListToAttrs; inherit (pkgs) haskellPackages; cfg = config.vim.languages.haskell; - - defaultServers = ["hls"]; - servers = { - hls = { - enable = true; - cmd = [(getExe pkgs.haskellPackages.haskell-language-server) "--debug"]; - filetypes = ["haskell" "lhaskell"]; - on_attach = - mkLuaInline - /* - lua - */ - '' - function(client, bufnr, ht) - default_on_attach(client, bufnr, ht) - local opts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set('n', 'cl', vim.lsp.codelens.run, opts) - vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts) - vim.keymap.set('n', 'ea', ht.lsp.buf_eval_all, opts) - vim.keymap.set('n', 'rr', ht.repl.toggle, opts) - vim.keymap.set('n', 'rf', function() - ht.repl.toggle(vim.api.nvim_buf_get_name(0)) - end, opts) - vim.keymap.set('n', 'rq', ht.repl.quit, opts) - end, - ''; - root_dir = - mkLuaInline - /* - lua - */ - '' - function(bufnr, on_dir) - local root_pattern = function(...) - local patterns = M.tbl_flatten { ... } - return function(startpath) - startpath = M.strip_archive_subpath(startpath) - for _, pattern in ipairs(patterns) do - local match = M.search_ancestors(startpath, function(path) - for _, p in ipairs(vim.fn.glob(table.concat({ escape_wildcards(path), pattern }, '/'), true, true)) do - if vim.uv.fs_stat(p) then - return path - end - end - end) - - if match ~= nil then - return match - end - end - end - end - - local fname = vim.api.nvim_buf_get_name(bufnr) - on_dir(root_pattern('hie.yaml', 'stack.yaml', 'cabal.project', '*.cabal', 'package.yaml')(fname)) - end - ''; - settings = { - haskell = { - formattingProvider = "ormolu"; - cabalFormattingProvider = "cabalfmt"; - }; - }; - }; - }; in { options.vim.languages.haskell = { enable = mkEnableOption "Haskell support"; @@ -93,11 +25,12 @@ in { }; lsp = { - enable = mkEnableOption "Haskell LSP support" // {default = config.vim.lsp.enable;}; - servers = mkOption { - description = "Haskell LSP server to use"; - type = listOf (enum (attrNames servers)); - default = defaultServers; + enable = mkEnableOption "LSP support for Haskell" // {default = config.vim.lsp.enable;}; + package = mkOption { + description = "Haskell LSP package or command to run the Haskell LSP"; + example = ''[ (lib.getExe pkgs.haskellPackages.haskell-language-server) "--debug" ]''; + default = haskellPackages.haskell-language-server; + type = either package (listOf str); }; }; @@ -119,21 +52,12 @@ in { }; }) - (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; - }) - (mkIf (cfg.dap.enable || cfg.lsp.enable) { vim = { startPlugins = ["haskell-tools-nvim"]; luaConfigRC.haskell-tools-nvim = entryAfter - ["lsp-servers"] + ["lsp-setup"] '' vim.g.haskell_tools = { ${optionalString cfg.lsp.enable '' @@ -143,8 +67,25 @@ in { enable = true, }, }, - -- Configured through vim.lsp.config - hls = {}, + hls = { + cmd = ${ + if isList cfg.lsp.package + then expToLua cfg.lsp.package + else ''{"${cfg.lsp.package}/bin/haskell-language-server-wrapper", "--lsp"}'' + }, + on_attach = function(client, bufnr, ht) + default_on_attach(client, bufnr, ht) + local opts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'cl', vim.lsp.codelens.run, opts) + vim.keymap.set('n', 'hs', ht.hoogle.hoogle_signature, opts) + vim.keymap.set('n', 'ea', ht.lsp.buf_eval_all, opts) + vim.keymap.set('n', 'rr', ht.repl.toggle, opts) + vim.keymap.set('n', 'rf', function() + ht.repl.toggle(vim.api.nvim_buf_get_name(0)) + end, opts) + vim.keymap.set('n', 'rq', ht.repl.quit, opts) + end, + }, ''} ${optionalString cfg.dap.enable '' dap = { diff --git a/modules/plugins/languages/hcl.nix b/modules/plugins/languages/hcl.nix index 10378383..e702170c 100644 --- a/modules/plugins/languages/hcl.nix +++ b/modules/plugins/languages/hcl.nix @@ -8,19 +8,22 @@ inherit (lib.options) mkEnableOption mkOption; inherit (lib.meta) getExe; inherit (lib.modules) mkIf mkMerge; - inherit (lib.types) package bool enum listOf; + inherit (lib.types) package bool enum; inherit (lib.nvim.types) mkGrammarOption; - inherit (lib.nvim.attrsets) mapListToAttrs; cfg = config.vim.languages.hcl; - defaultServers = ["terraform-ls"]; + defaultServer = "terraform-ls"; servers = { terraform-ls = { - enable = true; - cmd = [(getExe pkgs.terraform-ls) "serve"]; - filetypes = ["terraform" "terraform-vars"]; - root_markers = [".terraform" ".git"]; + package = pkgs.terraform-ls; + lspConfig = '' + lspconfig.terraformls.setup { + capabilities = capabilities, + on_attach=default_on_attach, + cmd = {"${lib.getExe cfg.lsp.package}", "serve"}, + } + ''; }; }; @@ -40,11 +43,12 @@ in { }; lsp = { - enable = mkEnableOption "HCL LSP support" // {default = config.vim.lsp.enable;}; - servers = mkOption { - description = "HCL LSP server to use"; - type = listOf (enum (attrNames servers)); - default = defaultServers; + enable = mkEnableOption "HCL LSP support (terraform-ls)" // {default = config.vim.lsp.enable;}; + # TODO: (maybe, is it better?) it would be cooler to use vscode-extensions.hashicorp.hcl probably, shouldn't be too hard + package = mkOption { + type = package; + default = servers.${defaultServer}.package; + description = "HCL language server package (terraform-ls)"; }; }; @@ -91,15 +95,6 @@ in { vim.treesitter.grammars = [cfg.treesitter.package]; }) - (mkIf cfg.lsp.enable { - vim.lsp.servers = - mapListToAttrs (n: { - name = n; - value = servers.${n}; - }) - cfg.lsp.servers; - }) - (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.sources = lib.optionalAttrs (! config.vim.languages.terraform.lsp.enable) {