noice: migrate to mkNeovimPlugin

This commit is contained in:
Austin Horstman 2024-10-27 20:02:15 -05:00
parent 89cad1aae7
commit 90d7deedc4
No known key found for this signature in database
2 changed files with 415 additions and 380 deletions

View file

@ -1,35 +1,100 @@
{ {
lib, lib,
config,
pkgs,
... ...
}: }:
# TODO: This uses a lot of types.anything because noice.nvim types are quite complex.
# It should be possible to map them to nix, but they would not map really well through
# toLuaObject, we would maybe need some ad-hoc pre-processing functions.
let let
inherit (lib) types; inherit (lib) types;
inherit (lib.nixvim) defaultNullOpts; inherit (lib.nixvim) defaultNullOpts;
in in
{ lib.nixvim.neovim-plugin.mkNeovimPlugin {
options.plugins.noice = lib.nixvim.neovim-plugin.extraOptionsOptions // { name = "noice";
enable = lib.mkEnableOption '' originalName = "noice.nvim";
noice.nvim, an experimental nvim UI. package = "noice-nvim";
Note that if treesitter is enabled you need the following parsers:
vim, regex, lua, bash, markdown, markdown_inline maintainers = [ lib.maintainers.khaneliman ];
description = ''
`noice.nvim`, an experimental Neovim UI.
> [!NOTE]
> If treesitter is enabled you need the following parsers:
> vim, regex, lua, bash, markdown, markdown_inline
''; '';
package = lib.mkPackageOption pkgs "noice" { # TODO: added 2024-10-27 remove after 24.11
default = [ deprecateExtraOptions = true;
"vimPlugins" optionsRenamedToSettings =
"noice-nvim" let
mkOptionPaths = map (lib.splitString ".");
in
mkOptionPaths [
"cmdline.enabled"
"cmdline.view"
"cmdline.opts"
"cmdline.format"
"messages.enabled"
"messages.view"
"messages.viewError"
"messages.viewWarn"
"messages.viewHistory"
"messages.viewSearch"
"popupmenu.enabled"
"popupmenu.backend"
"popupmenu.kindIcons"
"redirect"
"commands"
"notify.enabled"
"notify.view"
"lsp.progress.enabled"
"lsp.progress.format"
"lsp.progress.formatDone"
"lsp.progress.throttle"
"lsp.progress.view"
"lsp.override"
"lsp.hover.enabled"
"lsp.hover.view"
"lsp.hover.opts"
"lsp.signature.enabled"
"lsp.signature.autoOpen.enabled"
"lsp.signature.autoOpen.trigger"
"lsp.signature.autoOpen.luasnip"
"lsp.signature.autoOpen.throttle"
"lsp.signature.view"
"lsp.signature.opts"
"lsp.message.enabled"
"lsp.message.view"
"lsp.message.opts"
"lsp.documentation.view"
"lsp.documentation.opts"
"markdown.hover"
"markdown.highlights"
"health.checker"
"smartMove.enabled"
"smartMove.excludedFiletypes"
"presets"
"throttle"
"views"
"routes"
"status"
"format"
]; ];
};
settingsOptions = {
cmdline = { cmdline = {
enabled = defaultNullOpts.mkBool true "enables Noice cmdline UI"; enabled = defaultNullOpts.mkBool true "Enables `Noice` cmdline UI.";
view = defaultNullOpts.mkStr "cmdline_popup" "";
opts = defaultNullOpts.mkAttrsOf types.anything { } ""; view = defaultNullOpts.mkStr "cmdline_popup" ''
View for rendering the cmdline.
Change to `cmdline` to get a classic cmdline at the bottom.
'';
opts = defaultNullOpts.mkAttrsOf types.anything { } ''
Global options for the cmdline. See section on [views].
[views] https://github.com/folke/noice.nvim?tab=readme-ov-file#-views
'';
format = format =
defaultNullOpts.mkAttrsOf types.anything defaultNullOpts.mkAttrsOf types.anything
{ {
@ -66,6 +131,7 @@ in
}; };
input = { }; input = { };
} }
# TODO: cleanup
'' ''
conceal: (default=true) This will hide the text in the cmdline that matches the pattern. conceal: (default=true) This will hide the text in the cmdline that matches the pattern.
view: (default is cmdline view) view: (default is cmdline view)
@ -79,24 +145,30 @@ in
messages = { messages = {
enabled = defaultNullOpts.mkBool true '' enabled = defaultNullOpts.mkBool true ''
Enables the messages UI. Enables the messages UI.
NOTE: If you enable messages, then the cmdline is enabled automatically.
> [!NOTE] If you enable messages, then the cmdline is enabled automatically.
''; '';
view = defaultNullOpts.mkStr "notify" "default view for messages";
viewError = defaultNullOpts.mkStr "notify" "default view for errors"; view = defaultNullOpts.mkStr "notify" "Default view for messages.";
viewWarn = defaultNullOpts.mkStr "notify" "default view for warnings";
viewHistory = defaultNullOpts.mkStr "messages" "view for :messages"; view_error = defaultNullOpts.mkStr "notify" "Default view for errors.";
viewSearch = defaultNullOpts.mkStr "virtualtext" "view for search count messages";
view_warn = defaultNullOpts.mkStr "notify" "Default view for warnings.";
view_history = defaultNullOpts.mkStr "messages" "View for `:messages`.";
view_search = defaultNullOpts.mkStr "virtualtext" "View for search count messages.";
}; };
popupmenu = { popupmenu = {
enabled = defaultNullOpts.mkBool true "enables the Noice popupmenu UI"; enabled = defaultNullOpts.mkBool true "Enable the Noice popupmenu UI.";
backend = defaultNullOpts.mkEnumFirstDefault [ backend = defaultNullOpts.mkEnumFirstDefault [
"nui" "nui"
"cmp" "cmp"
] ""; ] "Backend to use to show regular cmdline completions.";
kindIcons = defaultNullOpts.mkNullable ( kindIcons = defaultNullOpts.mkNullableWithRaw (
with types; either bool (attrsOf anything) with types; either bool (attrsOf anything)
) { } "Icons for completion item kinds. set to `false` to disable icons"; ) { } "Icons for completion item kinds. Set to `false` to disable icons.";
}; };
redirect = defaultNullOpts.mkAttrsOf types.anything { redirect = defaultNullOpts.mkAttrsOf types.anything {
@ -104,7 +176,7 @@ in
filter = { filter = {
event = "msg_show"; event = "msg_show";
}; };
} "default options for require('noice').redirect"; } "Default options for `require('noice').redirect`.";
commands = defaultNullOpts.mkAttrsOf types.anything { commands = defaultNullOpts.mkAttrsOf types.anything {
history = { history = {
@ -167,72 +239,91 @@ in
reverse = true; reverse = true;
}; };
}; };
} "You can add any custom commands that will be available with `:Noice command`"; } "You can add any custom commands that will be available with `:Noice` command.";
notify = { notify = {
enabled = defaultNullOpts.mkBool true '' enabled = defaultNullOpts.mkBool true ''
Enable notification handling. Enable notification handling.
Noice can be used as `vim.notify` so you can route any notification like other messages. Noice can be used as `vim.notify` so you can route any notification like other messages.
Notification messages have their level and other properties set. Notification messages have their level and other properties set.
event is always "notify" and kind can be any log level as a string. event is always "notify" and kind can be any log level as a string.
The default routes will forward notifications to nvim-notify. The default routes will forward notifications to nvim-notify.
Benefit of using Noice for this is the routing and consistent history view. Benefit of using Noice for this is the routing and consistent history view.
''; '';
view = defaultNullOpts.mkStr "notify" "";
view = defaultNullOpts.mkStr "notify" "Notify backend to use.";
}; };
lsp = { lsp = {
progress = { progress = {
enabled = defaultNullOpts.mkBool true "enable LSP progress"; enabled = defaultNullOpts.mkBool true "Enable LSP progress.";
format = defaultNullOpts.mkNullable (with types; either str anything) "lsp_progress" '' format = defaultNullOpts.mkNullableWithRaw (with types; either str anything) "lsp_progress" ''
Lsp Progress is formatted using the builtins for lsp_progress Lsp Progress is formatted using the builtins for lsp_progress.
''; '';
formatDone = defaultNullOpts.mkNullable (with types; either str anything) "lsp_progress" "";
throttle = defaultNullOpts.mkNum (lib.literalExpression "1000 / 30") "frequency to update lsp progress message"; format_done =
defaultNullOpts.mkNullableWithRaw (with types; either str anything) "lsp_progress_done"
''
Lsp Progress is formatted using the builtins for lsp_progress.
'';
view = defaultNullOpts.mkStr "mini" ""; throttle = defaultNullOpts.mkNum (lib.literalExpression "1000 / 30") "Frequency to update lsp progress message.";
view = defaultNullOpts.mkStr "mini" "Lsp progress view backend.";
}; };
override = defaultNullOpts.mkAttrsOf types.bool { override = defaultNullOpts.mkAttrsOf types.bool {
"vim.lsp.util.convert_input_to_markdown_lines" = false; "vim.lsp.util.convert_input_to_markdown_lines" = false;
"vim.lsp.util.stylize_markdown" = false; "vim.lsp.util.stylize_markdown" = false;
"cmp.entry.get_documentation" = false; "cmp.entry.get_documentation" = false;
} ""; } "Functions to override and use Noice.";
hover = { hover = {
enabled = defaultNullOpts.mkBool true "enable hover UI"; enabled = defaultNullOpts.mkBool true "Enable hover UI.";
view = defaultNullOpts.mkStr (lib.literalMD "use defaults from documentation") ""; # TODO: description
opts = defaultNullOpts.mkAttrsOf types.anything { } "merged with defaults from documentation"; view = defaultNullOpts.mkStr (lib.literalMD "Use defaults from documentation") "When null, use defaults from documentation.";
opts =
defaultNullOpts.mkAttrsOf types.anything { }
"Options merged with defaults from documentation.";
}; };
signature = { signature = {
enabled = defaultNullOpts.mkBool true "enable signature UI"; enabled = defaultNullOpts.mkBool true "Enable signature UI.";
auto_open = {
enabled = defaultNullOpts.mkBool true "Enable automatic opening of signature help.";
trigger = defaultNullOpts.mkBool true "Automatically show signature help when typing a trigger character from the LSP.";
luasnip = defaultNullOpts.mkBool true "Will open signature help when jumping to Luasnip insert nodes.";
autoOpen = {
enabled = defaultNullOpts.mkBool true "";
trigger = defaultNullOpts.mkBool true "Automatically show signature help when typing a trigger character from the LSP";
luasnip = defaultNullOpts.mkBool true "Will open signature help when jumping to Luasnip insert nodes";
throttle = defaultNullOpts.mkNum 50 '' throttle = defaultNullOpts.mkNum 50 ''
Debounce lsp signature help request by 50ms Debounce lsp signature help request by 50ms.
''; '';
}; };
view = defaultNullOpts.mkStr null "when null, use defaults from documentation"; view = defaultNullOpts.mkStr null "When null, use defaults from documentation.";
opts = defaultNullOpts.mkAttrsOf types.anything { } "merged with defaults from documentation";
opts =
defaultNullOpts.mkAttrsOf types.anything { }
"Options merged with defaults from documentation.";
}; };
message = { message = {
enabled = defaultNullOpts.mkBool true "enable display of messages"; enabled = defaultNullOpts.mkBool true "Enable display of messages.";
view = defaultNullOpts.mkStr "notify" ""; view = defaultNullOpts.mkStr "notify" "Message backend to use.";
opts = defaultNullOpts.mkAttrsOf types.anything { } "";
opts = defaultNullOpts.mkAttrsOf types.anything { } "Options for message backend.";
}; };
documentation = { documentation = {
view = defaultNullOpts.mkStr "hover" ""; view = defaultNullOpts.mkStr "hover" "Documentation backend to use.";
opts = defaultNullOpts.mkAttrsOf types.anything { opts = defaultNullOpts.mkAttrsOf types.anything {
lang = "markdown"; lang = "markdown";
@ -243,7 +334,7 @@ in
concealcursor = "n"; concealcursor = "n";
conceallevel = 3; conceallevel = 3;
}; };
} ""; } "Options for documentation backend.";
}; };
}; };
@ -251,7 +342,7 @@ in
hover = defaultNullOpts.mkAttrsOf types.str { hover = defaultNullOpts.mkAttrsOf types.str {
"|(%S-)|".__raw = "vim.cmd.help"; # vim help links "|(%S-)|".__raw = "vim.cmd.help"; # vim help links
"%[.-%]%((%S-)%)".__raw = "require('noice.util').open"; # markdown links "%[.-%]%((%S-)%)".__raw = "require('noice.util').open"; # markdown links
} "set handlers for hover (lua code)"; } "Set handlers for hover.";
highlights = defaultNullOpts.mkAttrsOf types.str { highlights = defaultNullOpts.mkAttrsOf types.str {
"|%S-|" = "@text.reference"; "|%S-|" = "@text.reference";
@ -260,19 +351,20 @@ in
"^%s*(Return:)" = "@text.title"; "^%s*(Return:)" = "@text.title";
"^%s*(See also:)" = "@text.title"; "^%s*(See also:)" = "@text.title";
"{%S-}" = "@parameter"; "{%S-}" = "@parameter";
} "set highlight groups"; } "Set highlight groups.";
}; };
health = { health = {
checker = defaultNullOpts.mkBool true "Disable if you don't want health checks to run"; checker = defaultNullOpts.mkBool true "Enables running health checks.";
}; };
smartMove = { smart_move = {
enabled = defaultNullOpts.mkBool true '' enabled = defaultNullOpts.mkBool true ''
Noice tries to move out of the way of existing floating windows. Noice tries to move out of the way of existing floating windows.
You can disable this behaviour here You can disable this behaviour here.
''; '';
excludedFiletypes =
excluded_filetypes =
defaultNullOpts.mkListOf types.str defaultNullOpts.mkListOf types.str
[ [
"cmp_menu" "cmp_menu"
@ -280,7 +372,7 @@ in
"notify" "notify"
] ]
'' ''
add any filetypes here, that shouldn't trigger smart move Filetypes that shouldn't trigger smart move.
''; '';
}; };
@ -293,129 +385,69 @@ in
inc_rename = false; inc_rename = false;
lsp_doc_border = false; lsp_doc_border = false;
} }
" ''
you can enable a preset by setting it to true, or a table that will override the preset You can enable a preset by setting it to `true`, or a table that will override
config. you can also add custom presets that you can enable/disable with enabled=true the preset config.
";
throttle = defaultNullOpts.mkNum (lib.literalExpression "1000 / 30") '' You can also add custom presets that you can enable/disable with `enabled=true`.
how frequently does Noice need to check for ui updates? This has no effect when in blocking
mode
''; '';
views = defaultNullOpts.mkAttrsOf types.anything { } ""; throttle = defaultNullOpts.mkNum (lib.literalExpression "1000 / 30") ''
routes = defaultNullOpts.mkListOf (types.attrsOf types.anything) [ ] ""; How frequently does Noice need to check for ui updates?
status = defaultNullOpts.mkAttrsOf types.anything { } "";
format = defaultNullOpts.mkAttrsOf types.anything { } "";
};
config = This has no effect when in blocking mode.
let '';
cfg = config.plugins.noice;
setupOptions = { views = defaultNullOpts.mkAttrsOf types.anything { } ''
inherit (cfg) A view is a combination of a backend and options.
presets
views Noice comes with the following built-in backends:
routes
status - `popup`: powered by nui.nvim
format - `split`: powered by nui.nvim
; - `notify`: powered by nvim-notify
cmdline = { - `virtualtext`: shows the message as virtualtext (for example for search_count)
inherit (cfg.cmdline) - `mini`: similar to notifier.nvim & fidget.nvim
enabled - `notify_send`: generate a desktop notification
view '';
opts
format routes = defaultNullOpts.mkListOf (types.attrsOf types.anything) [ ] ''
; Route options can be any of the view options or `skip` or `stop`.
};
messages = A route has a filter, view and optional opts attribute.
let
cfgM = cfg.messages; - `view`: one of the views (built-in or custom)
in - `filter` a filter for messages matching this route
{ - `opts`: options for the view and the route
inherit (cfgM) enabled view; '';
view_error = cfgM.viewError;
view_warn = cfgM.viewWarn; status = defaultNullOpts.mkAttrsOf types.anything { } ''
view_history = cfgM.viewHistory; Noice comes with the following statusline components:
view_search = cfgM.viewSearch;
}; - `ruler`
popupmenu = - `message`: last line of the last message (event=show_msg)
let - `command`: showcmd
cfgP = cfg.popupmenu; - `mode`: showmode (@recording messages)
in - `search`: search count messages
{ '';
inherit (cfgP) enabled backend;
kind_icons = cfgP.kindIcons; format = defaultNullOpts.mkAttrsOf types.anything { } ''
}; Formatters are used in format definitions.
inherit (cfg) redirect commands;
notify = { Noice includes the following formatters:
inherit (cfg.notify) enabled view;
}; - `level`: message level with optional icon and hl_group per level
lsp = - `text`: any text with optional hl_group
let - `title`: message title with optional hl_group
cfgL = cfg.lsp; - `event`: message event with optional hl_group
in - `kind`: message kind with optional hl_group
{ - `date`: formatted date with optional date format string
progress = - `message`: message content itself with optional hl_group to override message highlights
let - `confirm`: only useful for confirm messages. Will format the choices as buttons.
cfgLP = cfgL.progress; - `cmdline`: will render the cmdline in the message that generated the message.
in - `progress`: progress bar used by lsp progress
{ - `spinner`: spinners used by lsp progress
inherit (cfgLP) - `data`: render any custom data from Message.opts. Useful in combination with the opts passed to vim.notify
enabled
format
throttle
view
;
format_done = cfgLP.formatDone;
};
inherit (cfgL) override;
hover = {
inherit (cfgL.hover) enabled view opts;
};
signature =
let
cfgLS = cfgL.signature;
in
{
inherit (cfgLS) enabled view opts;
auto_open = {
inherit (cfgLS.autoOpen)
enabled
trigger
luasnip
throttle
;
};
};
message = {
inherit (cfgL.message) enabled view opts;
};
documentation = {
inherit (cfgL.documentation) view opts;
};
};
markdown = {
inherit (cfg.markdown) hover highlights;
};
health = {
inherit (cfg.health) checker;
};
smart_move =
let
cfgS = cfg.smartMove;
in
{
inherit (cfgS) enabled;
excluded_filetypes = cfgS.excludedFiletypes;
};
};
in
lib.mkIf cfg.enable {
# nui-nvim & nvim-notify are dependencies of the vimPlugins.noice-nvim package
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require("noice").setup(${lib.nixvim.toLuaObject setupOptions})
''; '';
}; };
} }

View file

@ -6,6 +6,8 @@
defaults = { defaults = {
plugins.noice = { plugins.noice = {
enable = true; enable = true;
settings = {
cmdline = { cmdline = {
enabled = true; enabled = true;
view = "cmdline_popup"; view = "cmdline_popup";
@ -48,15 +50,15 @@
messages = { messages = {
enabled = true; enabled = true;
view = "notify"; view = "notify";
viewError = "notify"; view_error = "notify";
viewWarn = "notify"; view_warn = "notify";
viewHistory = "messages"; view_history = "messages";
viewSearch = "virtualtext"; view_search = "virtualtext";
}; };
popupmenu = { popupmenu = {
enabled = true; enabled = true;
backend = "nui"; backend = "nui";
kindIcons = { }; kind_icons = { };
}; };
redirect = { redirect = {
view = "popup"; view = "popup";
@ -134,7 +136,7 @@
progress = { progress = {
enabled = true; enabled = true;
format = "lsp_progress"; format = "lsp_progress";
formatDone = "lsp_progress_done"; format_done = "lsp_progress_done";
throttle = 1000 / 30; throttle = 1000 / 30;
view = "mini"; view = "mini";
}; };
@ -150,7 +152,7 @@
}; };
signature = { signature = {
enabled = true; enabled = true;
autoOpen = { auto_open = {
enabled = true; enabled = true;
trigger = true; trigger = true;
luasnip = true; luasnip = true;
@ -195,9 +197,9 @@
health = { health = {
checker = true; checker = true;
}; };
smartMove = { smart_move = {
enabled = true; enabled = true;
excludedFiletypes = [ excluded_filetypes = [
"cmp_menu" "cmp_menu"
"cmp_docs" "cmp_docs"
"notify" "notify"
@ -217,4 +219,5 @@
format = { }; format = { };
}; };
}; };
};
} }