This commit is contained in:
Ching Pei Yang 2024-06-28 22:12:14 +02:00 committed by GitHub
commit fc6349736d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 140 additions and 66 deletions

View File

@ -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):

View File

@ -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})
'';
};
};

View File

@ -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";
};
};
};
}