From 9b48c30e206b2c0e2c73cf85243299f50ee092be Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:02:48 +0200 Subject: [PATCH] Feat noice setup opts (#297) * noice: add setupOpts * noice: add filter * noice: use setupOpts * docs: update release notes * noice: allow null option * noice: add descriptions for some options --- docs/release-notes/rl-0.7.md | 1 + modules/plugins/ui/noice/config.nix | 66 +------------ modules/plugins/ui/noice/noice.nix | 139 +++++++++++++++++++++++++++- 3 files changed, 140 insertions(+), 66 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index d3676aa..e283ab3 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -30,6 +30,7 @@ Release notes for release 0.7 - Deprecate use of `__empty` to define empty tables in lua. Empty attrset are no longer filtered and thus should be used instead. - Add dap-go for better dap configurations +- Make noice.nvim customizable [jacekpoz](https://github.com/jacekpoz): 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 b361d45..bf16e3f 100644 --- a/modules/plugins/ui/noice/noice.nix +++ b/modules/plugins/ui/noice/noice.nix @@ -1,7 +1,142 @@ -{lib, ...}: let - inherit (lib.options) mkEnableOption; +{ + lib, + config, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) anything nullOr listOf submodule str; + 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 = "󰋖"; + }; + }; + }; + + routes = mkOption { + description = "How to route messages"; + type = listOf (submodule { + options = { + view = mkOption { + description = "how this route is viewed"; + type = nullOr str; + default = null; + }; + + filter = mkOption { + description = "a filter for messages matching this route"; + type = anything; + }; + + opts = mkOption { + description = "options for the view and the route"; + type = nullOr anything; + default = null; + }; + }; + }); + + default = [ + { + filter = { + event = "msg_show"; + kind = ""; + find = "written"; + }; + opts = {skip = true;}; + } + ]; + defaultText = "Hide written messages"; + }; + }; }; }