From a0a57757a07941c5523e646f0a97176492704bd4 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 12 Dec 2024 20:16:27 +0300 Subject: [PATCH 1/3] wrapper/rc: explicitly add `tabstop` & `shiftwidth` to `vim.options` Defaults are taken from Neovim's :help tags for those options to avoid intrusive/confusing behaviour. --- modules/wrapper/rc/options.nix | 48 ++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/modules/wrapper/rc/options.nix b/modules/wrapper/rc/options.nix index ab541419..df3831ec 100644 --- a/modules/wrapper/rc/options.nix +++ b/modules/wrapper/rc/options.nix @@ -126,16 +126,14 @@ in { example = {"some_variable" = 42;}; description = '' - An attribute set containing global variable values - for storing vim variables as early as possible. If - populated, this option will set vim variables in the - built luaConfigRC as the first item. + A freeform attribute set containing global variable values for setting vim + variables as early as possible. If populated, this option will set vim variables + in the built {option}`luaConfigRC` as the first item. ::: {.note} - `{foo = "bar";}` will set `vim.g.foo` to "bar", where - the type of `bar` in the resulting Lua value will be - inferred from the type of the value in the `{name = value;}` - pair passed to the option. + `{foo = "bar";}` will set `vim.g.foo` to "bar", where the type of `bar` in the + resulting Lua value will be inferred from the type of the value in the + `{name = value;}` pair passed to the option. ::: ''; }; @@ -212,21 +210,39 @@ in { default = true; description = "Enable word wrapping."; }; + + tabstop = mkOption { + type = int; + default = 8; # Neovim default + description = '' + Number of spaces that a `` in the file counts for. Also see + the {command}`:retab` command, and the {option}`softtabstop` option. + ''; + }; + + shiftwidth = mkOption { + type = int; + default = 8; # Neovim default + description = '' + Number of spaces to use for each step of (auto)indent. Used for + {option}`cindent`, `>>`, `<<`, etc. + + When zero the {option}`tabstop` value will be used. + ''; + }; }; }; example = {visualbell = true;}; description = '' - An attribute set containing vim options to be set - as early as possible. If populated, this option will - set vim options in the built luaConfigRC after `basic` - and before `pluginConfigs` DAG entries. + A freeform attribute set containing vim options to be set as early as possible. + If populated, this option will set vim options in the built {option}`luaConfigRC` + after `basic` and before `pluginConfigs` DAG entries. ::: {.note} - `{foo = "bar";}` will set `vim.o.foo` to "bar", where - the type of `bar` in the resulting Lua value will be - inferred from the type of the value in the`{name = value;}` - pair passed to the option. + `{foo = "bar";}` will set `vim.o.foo` to "bar", where the type of `bar` in the + resulting Lua value will be inferred from the type of the value in the + `{name = value;}` pair passed to the option. ::: ''; }; From e715463257abd42ec6726a10a5cb2177ebda0c00 Mon Sep 17 00:00:00 2001 From: Artur Manuel Date: Fri, 20 Dec 2024 03:50:38 +0000 Subject: [PATCH 2/3] plugins/languages: add haskell support (#499) * plugins/languages: add haskell support Closes #426 * fix docs --------- Co-authored-by: Artur Manuel Co-authored-by: raf --- configuration.nix | 1 + docs/release-notes/rl-0.8.md | 6 ++ flake.lock | 17 +++++ flake.nix | 5 ++ modules/plugins/languages/default.nix | 1 + modules/plugins/languages/haskell.nix | 104 ++++++++++++++++++++++++++ modules/plugins/languages/rust.nix | 4 +- 7 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 modules/plugins/languages/haskell.nix diff --git a/configuration.nix b/configuration.nix index 3802f758..3be1d39b 100644 --- a/configuration.nix +++ b/configuration.nix @@ -79,6 +79,7 @@ isMaximal: { dart.enable = false; ocaml.enable = false; elixir.enable = false; + haskell.enable = false; tailwind.enable = false; svelte.enable = false; diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 52a9ae64..36209ff7 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -8,3 +8,9 @@ `languages.typst.extensions.typst-preview-nvim`. - Add a search widget to the options page in the nvf manual. + +[amadaluzia](https://github.com/amadaluzia): + +[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim + +- Add Haskell support under `vim.languages.haskell` using [haskell-tools.nvim] diff --git a/flake.lock b/flake.lock index d5532b4b..dc9cd81a 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index 65c802f2..161ba43f 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; }; } diff --git a/modules/plugins/languages/default.nix b/modules/plugins/languages/default.nix index a69d3e8d..48945b38 100644 --- a/modules/plugins/languages/default.nix +++ b/modules/plugins/languages/default.nix @@ -14,6 +14,7 @@ in { ./hcl.nix ./kotlin.nix ./html.nix + ./haskell.nix ./java.nix ./lua.nix ./markdown.nix diff --git a/modules/plugins/languages/haskell.nix b/modules/plugins/languages/haskell.nix new file mode 100644 index 00000000..f8e17b75 --- /dev/null +++ b/modules/plugins/languages/haskell.nix @@ -0,0 +1,104 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (builtins) isList; + inherit (lib.types) either package listOf str; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.strings) optionalString; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.nvim.types) mkGrammarOption; + inherit (lib.nvim.dag) entryAfter; + inherit (lib.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"; + example = ''[ (lib.getExe pkgs.haskellPackages.haskell-language-server) "--debug" ]''; + 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 = + entryAfter + ["lsp-setup"] + '' + 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', '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 = { + cmd = ${ + if isList cfg.dap.package + then expToLua cfg.dap.package + else ''${cfg.dap.package}/bin/haskell-debug-adapter'' + }, + }, + ''} + } + ''; + }; + }) + ]); +} diff --git a/modules/plugins/languages/rust.nix b/modules/plugins/languages/rust.nix index ec1887cb..7e9cb627 100644 --- a/modules/plugins/languages/rust.nix +++ b/modules/plugins/languages/rust.nix @@ -13,7 +13,7 @@ inherit (lib.types) bool package str listOf either enum; inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.lua) expToLua; - inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.dag) entryAfter entryAnywhere; cfg = config.vim.languages.rust; @@ -127,7 +127,7 @@ in { vim = { startPlugins = ["rustaceanvim"]; - luaConfigRC.rustaceanvim = entryAnywhere '' + pluginRC.rustaceanvim = entryAfter ["lsp-setup"] '' vim.g.rustaceanvim = { ${optionalString cfg.lsp.enable '' -- LSP From 99a4eafa34450fc94e43e3f0ed4df559a40f9b35 Mon Sep 17 00:00:00 2001 From: Yoni Firroloni Date: Fri, 20 Dec 2024 04:11:18 +0000 Subject: [PATCH 3/3] languages/typescript: prevent ts_ls from formatting (#495) * ts_ls: prevent from formatting prevent ts_ls from touching the formating. ts formatting: remove useless indent * fix unnecessary whitespace --------- Co-authored-by: raf --- modules/plugins/languages/ts.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/plugins/languages/ts.nix b/modules/plugins/languages/ts.nix index 8843cc46..2530d352 100644 --- a/modules/plugins/languages/ts.nix +++ b/modules/plugins/languages/ts.nix @@ -23,8 +23,11 @@ package = pkgs.typescript-language-server; lspConfig = '' lspconfig.ts_ls.setup { - capabilities = capabilities; - on_attach = attach_keymaps, + capabilities = capabilities, + on_attach = function(client, bufnr) + attach_keymaps(client, bufnr); + client.server_capabilities.documentFormattingProvider = false; + end, cmd = ${ if isList cfg.lsp.package then expToLua cfg.lsp.package @@ -79,6 +82,7 @@ ls_sources, null_ls.builtins.formatting.prettier.with({ command = "${cfg.format.package}/bin/prettier", + filetypes = { "typescript" }, }) ) '';