From 72e39a910ceff7e0921213fca1445ac37c6a09c0 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 1 May 2024 23:03:36 +0200 Subject: [PATCH 1/6] noice: add setupOpts --- modules/plugins/ui/noice/noice.nix | 105 ++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index b361d45..d1e3970 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -1,7 +1,108 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption; +{ + lib, + config, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) anything nullOr; + inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.nvim.config) mkBool; in { options.vim.ui.noice = { enable = mkEnableOption "noice.nvim UI modification library"; + + setupOpts = mkPluginSetupOption "noice.nvim" { + lsp = { + override = { + "vim.lsp.util.convert_input_to_markdown_lines" = + mkBool true "override the default lsp markdown formatter with Noice"; + + "vim.lsp.util.stylize_markdown" = + mkBool true "override the lsp markdown formatter with Noice"; + + "cmp.entry.get_documentation" = + mkBool (config.vim.autocomplete.type == "nvim-cmp") "override cmp documentation with Noice"; + }; + + signature = { + enabled = mkEnableOption "signature help"; + }; + }; + + presets = { + bottom_search = mkBool true "use a classic bottom cmdline for search"; + command_palette = mkBool true "position the cmdline and popupmenu together"; + long_message_to_split = mkBool true "long messages will be sent to a split"; + inc_rename = mkBool false "enables an input dialog for inc-rename.nvim"; + lsp_doc_border = + mkBool config.vim.ui.borders.enable "add a border to hover docs and signature help"; + }; + + # TODO: is it possible to write a submodule for this? + format = { + cmdline = mkOption { + description = "formatting options for the cmdline"; + type = nullOr anything; + default = { + pattern = "^:"; + icon = ""; + lang = "vim"; + }; + }; + + search_down = mkOption { + description = "formatting options for search_down"; + type = nullOr anything; + default = { + kind = "search"; + pattern = "^/"; + icon = " "; + lang = "regex"; + }; + }; + + search_up = mkOption { + description = "formatting options for search_up"; + type = nullOr anything; + default = { + kind = "search"; + pattern = "^%?"; + icon = " "; + lang = "regex"; + }; + }; + + filter = mkOption { + description = "formatting options for filter"; + type = nullOr anything; + default = { + pattern = "^:%s*!"; + icon = ""; + lang = "bash"; + }; + }; + + lua = mkOption { + description = "formatting options for lua"; + type = nullOr anything; + default = { + pattern = "^:%s*lua%s+"; + icon = ""; + lang = "lua"; + }; + }; + + help = mkOption { + description = "formatting options for help"; + type = nullOr anything; + default = { + pattern = "^:%s*he?l?p?%s+"; + icon = "󰋖"; + }; + }; + }; + + # TODO: messages, routes + }; }; } From 1b96dab8770067899524b98abe33b723c5075078 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 22 May 2024 19:58:01 +0200 Subject: [PATCH 2/6] noice: add filter --- modules/plugins/ui/noice/noice.nix | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index d1e3970..f3af447 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -4,7 +4,7 @@ ... }: let inherit (lib.options) mkEnableOption mkOption; - inherit (lib.types) anything nullOr; + inherit (lib.types) anything nullOr listOf submodule str; inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.nvim.config) mkBool; in { @@ -102,7 +102,38 @@ in { }; }; - # TODO: messages, routes + routes = mkOption { + description = "How to route messages"; + type = listOf (submodule { + options = { + view = mkOption { + description = ""; + type = str; + }; + + filter = mkOption { + description = ""; + type = anything; + }; + + opts = mkOption { + description = ""; + type = nullOr anything; + }; + }; + }); + + default = [ + { + filter = { + event = "msg_show"; + kind = ""; + find = "written"; + }; + opts = {skip = true;}; + } + ]; + }; }; }; } From 718b48cfdbf7043c3e4300cc7a9d56c04cea4d23 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 22 May 2024 20:00:29 +0200 Subject: [PATCH 3/6] noice: use setupOpts --- modules/plugins/ui/noice/config.nix | 66 +---------------------------- modules/plugins/ui/noice/noice.nix | 1 + 2 files changed, 3 insertions(+), 64 deletions(-) diff --git a/modules/plugins/ui/noice/config.nix b/modules/plugins/ui/noice/config.nix index 8d84584..d3ebe01 100644 --- a/modules/plugins/ui/noice/config.nix +++ b/modules/plugins/ui/noice/config.nix @@ -6,13 +6,11 @@ }: let inherit (lib.modules) mkIf; inherit (lib.lists) optionals; - inherit (lib.strings) optionalString; - inherit (lib.trivial) boolToString; + inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.dag) entryAnywhere; cfg = config.vim.ui.noice; tscfg = config.vim.treesitter; - cmptype = config.vim.autocomplete.type; defaultGrammars = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [vim regex lua bash markdown]; in { @@ -26,67 +24,7 @@ in { treesitter.grammars = optionals tscfg.addDefaultGrammars defaultGrammars; luaConfigRC.noice-nvim = entryAnywhere '' - require("noice").setup({ - lsp = { - override = { - ["vim.lsp.util.convert_input_to_markdown_lines"] = true, - ["vim.lsp.util.stylize_markdown"] = true, - ${optionalString (cmptype == "nvim-cmp") "[\"cmp.entry.get_documentation\"] = true,"} - }, - - signature = { - enabled = false, -- FIXME: enabling this file throws an error which I couldn't figure out - }, - }, - - hover = { - enabled = true, - silent = false, -- set to true to not show a message if hover is not available - view = nil, -- when nil, use defaults from documentation - opts = {}, -- merged with defaults from documentation - }, - - presets = { - bottom_search = true, -- use a classic bottom cmdline for search - command_palette = true, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = ${boolToString config.vim.ui.borders.enable}, -- add a border to hover docs and signature help - }, - - format = { - cmdline = { pattern = "^:", icon = "", lang = "vim" }, - search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" }, - search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" }, - filter = { pattern = "^:%s*!", icon = "", lang = "bash" }, - lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" }, - help = { pattern = "^:%s*he?l?p?%s+", icon = "󰋖" }, - input = {}, - }, - - messages = { - -- NOTE: If you enable messages, then the cmdline is enabled automatically. - -- This is a current Neovim limitation. - enabled = true, -- enables the Noice messages UI - view = "notify", -- default view for messages - view_error = "notify", -- view for errors - view_warn = "notify", -- view for warnings - view_history = "messages", -- view for :messages - view_search = "virtualtext", -- view for search count messages. Set to `false` to disable - }, - - -- Hide written messages - routes = { - { - filter = { - event = "msg_show", - kind = "", - find = "written", - }, - opts = { skip = true }, - }, - }, - }) + require("noice").setup(${toLuaObject cfg.setupOpts}) ''; }; }; diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index f3af447..9f30d7c 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -133,6 +133,7 @@ in { opts = {skip = true;}; } ]; + defaultText = "Hide written messages"; }; }; }; From d53040dd346037dbbc73eb1e55fad06be3104c0f Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Wed, 22 May 2024 21:37:35 +0200 Subject: [PATCH 4/6] docs: update release notes --- docs/release-notes/rl-0.7.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 1d76d53..9ba405e 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -29,6 +29,7 @@ Release notes for release 0.7 - Fix broken treesitter-context keybinds in visual mode - Deprecate use of `__empty` to define empty tables in lua. Empty attrset are no longer filtered and thus should be used instead. +- Make noice.nvim customizable [jacekpoz](https://github.com/jacekpoz): From 44c8acdffa4bdfafd5ab0bba59e09e4ad3fc4fa3 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:29:18 +0200 Subject: [PATCH 5/6] noice: allow null option --- modules/plugins/ui/noice/noice.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index 9f30d7c..0fb52cd 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -108,7 +108,8 @@ in { options = { view = mkOption { description = ""; - type = str; + type = nullOr str; + default = null; }; filter = mkOption { @@ -119,6 +120,7 @@ in { opts = mkOption { description = ""; type = nullOr anything; + default = null; }; }; }); From df565e3416413fc2f18a653e6730ad2de4e85b6a Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Thu, 27 Jun 2024 10:43:42 +0200 Subject: [PATCH 6/6] noice: add descriptions for some options --- modules/plugins/ui/noice/noice.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/plugins/ui/noice/noice.nix b/modules/plugins/ui/noice/noice.nix index 0fb52cd..bf16e3f 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -107,18 +107,18 @@ in { type = listOf (submodule { options = { view = mkOption { - description = ""; + description = "how this route is viewed"; type = nullOr str; default = null; }; filter = mkOption { - description = ""; + description = "a filter for messages matching this route"; type = anything; }; opts = mkOption { - description = ""; + description = "options for the view and the route"; type = nullOr anything; default = null; };