diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index 4dd694f1..7b784b9a 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -207,6 +207,8 @@ - Lazy-load `nvim-autopairs` plugin when using `vim.autopairs.nvim-autopairs.enable` +- Added support for neovim 0.12's `ui2` feature via `vim.ui.ui2` + [Machshev](https://github.com/machshev): - Added `ruff` and `ty` LSP support for Python under `programs.python`. diff --git a/modules/plugins/ui/default.nix b/modules/plugins/ui/default.nix index d7d7592f..193070d9 100644 --- a/modules/plugins/ui/default.nix +++ b/modules/plugins/ui/default.nix @@ -12,5 +12,6 @@ ./notifications ./nvim-ufo ./smartcolumn + ./ui2 ]; } diff --git a/modules/plugins/ui/ui2/config.nix b/modules/plugins/ui/ui2/config.nix new file mode 100644 index 00000000..52676b43 --- /dev/null +++ b/modules/plugins/ui/ui2/config.nix @@ -0,0 +1,19 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkIf; + inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; + + cfg = config.vim.ui.ui2; +in { + config = mkIf cfg.enable { + vim = { + luaConfigRC.ui2 = entryAnywhere '' + require('vim._core.ui2').enable(${toLuaObject (cfg.setupOpts // {enable = lib.mkForce true;})}) + ''; + }; + }; +} diff --git a/modules/plugins/ui/ui2/default.nix b/modules/plugins/ui/ui2/default.nix new file mode 100644 index 00000000..c727477e --- /dev/null +++ b/modules/plugins/ui/ui2/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./config.nix + ./ui2.nix + ]; +} diff --git a/modules/plugins/ui/ui2/ui2.nix b/modules/plugins/ui/ui2/ui2.nix new file mode 100644 index 00000000..02d09871 --- /dev/null +++ b/modules/plugins/ui/ui2/ui2.nix @@ -0,0 +1,77 @@ +{lib, ...}: let + inherit (lib.options) mkEnableOption mkOption; + inherit + (lib.types) + nullOr + oneOf + enum + attrsOf + number + int + ; + inherit (lib.nvim.types) mkPluginSetupOption; + + # Top-level targets only accepts `cmd` and `msg`, which is shorter, so we define that one + # inline below. This is the accepted targets for ui2 messages when defining it as a table + # or an attrset in Nix. + msgTargetEnum = enum [ + "cmd" + "msg" + "pager" + ]; + + heightOption = target: default: + mkOption { + description = "Maximum height for the ${target} window"; + type = number; + inherit default; + }; +in { + options.vim.ui.ui2 = { + enable = mkEnableOption "the Neovim 0.12+ experimental built-in UI overhaul"; + + setupOpts = mkPluginSetupOption "ui2" { + msg = { + targets = mkOption { + description = '' + Default message target, either commandline or a separate window. + Can alternatively specify different targets for different kinds of messages as an attrset. + See [`:h ui-messages`](https://neovim.io/doc/user/api-ui-events/#ui-messages) + for the different message types you can use in this configration. + Separating the message types also allows sending to a 'pager' output. + ''; + type = nullOr (oneOf [ + (enum [ + "cmd" + "msg" + ]) + (attrsOf msgTargetEnum) + ]); + default = "cmd"; + example = { + bufwrite = "cmd"; + quickfix = "msg"; + }; + }; + cmd = { + height = heightOption "cmdline" 0.5; + }; + dialog = { + height = heightOption "dialog" 0.5; + }; + msg = { + height = heightOption "msg" 0.5; + timeout = mkOption { + description = "Time a message is visible in the message window"; + type = int; + default = 4000; + example = 1500; + }; + }; + pager = { + height = heightOption "pager" 1; + }; + }; + }; + }; +}