Merge pull request #572 from NotAShelf/lightbulb-cleanup

lsp/lightbulb: cleanup; modularize autocommand behaviour
This commit is contained in:
raf 2025-01-25 16:57:14 +03:00 committed by GitHub
commit 3a6d2f7294
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 11 deletions

View file

@ -31,6 +31,12 @@
your Editorconfig configuration, or use an autocommand to set indentation your Editorconfig configuration, or use an autocommand to set indentation
values for buffers with the Nix filetype. values for buffers with the Nix filetype.
- Add [](#opt-vim.lsp.lightbulb.autocmd.enable) for manually managing the
previously managed lightbulb autocommand.
- A warning will occur if [](#opt-vim.lsp.lightbulb.autocmd.enable) and
`vim.lsp.lightbulb.setupOpts.autocmd.enabled` are both set at the same time.
Pick only one.
[amadaluzia](https://github.com/amadaluzia): [amadaluzia](https://github.com/amadaluzia):
[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim [haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim
@ -59,7 +65,8 @@
- Add `vim.snippets.luasnip.setupOpts`, which was previously missing. - Add `vim.snippets.luasnip.setupOpts`, which was previously missing.
- Add `"prettierd"` as a formatter option in - Add `"prettierd"` as a formatter option in
`vim.languages.markdown.format.type`. `vim.languages.markdown.format.type`.
- Add the following plugins from [mini.nvim](https://github.com/echasnovski/mini.nvim) - Add the following plugins from
[mini.nvim](https://github.com/echasnovski/mini.nvim)
- `mini.ai` - `mini.ai`
- `mini.align` - `mini.align`
- `mini.animate` - `mini.animate`
@ -102,7 +109,8 @@
- `mini.trailspace` - `mini.trailspace`
- `mini.visits` - `mini.visits`
- Add [fzf-lua](https://github.com/ibhagwan/fzf-lua) in `vim.fzf-lua` - Add [fzf-lua](https://github.com/ibhagwan/fzf-lua) in `vim.fzf-lua`
- Add [rainbow-delimiters](https://github.com/HiPhish/rainbow-delimiters.nvim) in `vim.visuals.rainbow-delimiters` - Add [rainbow-delimiters](https://github.com/HiPhish/rainbow-delimiters.nvim)
in `vim.visuals.rainbow-delimiters`
- Add options to define highlights under [](#opt-vim.highlight) - Add options to define highlights under [](#opt-vim.highlight)
[kaktu5](https://github.com/kaktu5): [kaktu5](https://github.com/kaktu5):
@ -125,5 +133,5 @@
[ARCIII](https://github.com/ArmandoCIII): [ARCIII](https://github.com/ArmandoCIII):
- Add `vim.languages.zig.dap` support through pkgs.lldb dap adapter. - Add `vim.languages.zig.dap` support through pkgs.lldb dap adapter. Code
Code Inspiration from `vim.languages.clang.dap` implementation. Inspiration from `vim.languages.clang.dap` implementation.

View file

@ -4,6 +4,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
@ -12,13 +13,29 @@ in {
config = mkIf (cfg.enable && cfg.lightbulb.enable) { config = mkIf (cfg.enable && cfg.lightbulb.enable) {
vim = { vim = {
startPlugins = ["nvim-lightbulb"]; startPlugins = ["nvim-lightbulb"];
pluginRC.lightbulb = entryAnywhere '' pluginRC.lightbulb = entryAnywhere ''
vim.api.nvim_command('autocmd CursorHold,CursorHoldI * lua require\'nvim-lightbulb\'.update_lightbulb()') local nvim_lightbulb = require("nvim-lightbulb")
nvim_lightbulb.setup(${toLuaObject cfg.lightbulb.setupOpts})
-- Enable trouble diagnostics viewer ${optionalString cfg.lightbulb.autocmd.enable ''
require'nvim-lightbulb'.setup(${toLuaObject cfg.lightbulb.setupOpts}) vim.api.nvim_create_autocmd(${toLuaObject cfg.lightbulb.autocmd.events}, {
pattern = ${toLuaObject cfg.lightbulb.autocmd.pattern},
callback = function()
nvim_lightbulb.update_lightbulb()
end,
})
''}
''; '';
}; };
warnings = [
# This could have been an assertion, but the chances of collision is very low and asserting here
# might be too dramatic. Let's only warn the user, *in case* this occurs and is not intended. No
# error will be thrown if 'lightbulb.setupOpts.autocmd.enable' has not been set by the user.
(mkIf (cfg.lightbulb.autocmd.enable -> (cfg.lightbulb.setupOpts.autocmd.enabled or false)) ''
Both 'vim.lsp.lightbulb.autocmd.enable' and 'vim.lsp.lightbulb.setupOpts.autocmd.enable' are set
simultaneously. This might have performance implications due to frequent updates. Please set only
one option to handle nvim-lightbulb autocmd.
'')
];
}; };
} }

View file

@ -1,11 +1,29 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.nvim.types) mkPluginSetupOption; inherit (lib.types) listOf str either;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
in { in {
options.vim.lsp = { options.vim.lsp = {
lightbulb = { lightbulb = {
enable = mkEnableOption "Lightbulb for code actions. Requires an emoji font"; enable = mkEnableOption "Lightbulb for code actions. Requires an emoji font";
setupOpts = mkPluginSetupOption "nvim-lightbulb" {}; setupOpts = mkPluginSetupOption "nvim-lightbulb" {};
autocmd = {
enable = mkEnableOption "updating lightbulb glyph automatically" // {default = true;};
events = mkOption {
type = listOf str;
default = ["CursorHold" "CursorHoldI"];
description = "Events on which to update nvim-lightbulb glyphs";
};
pattern = mkOption {
type = either str luaInline;
default = "*";
description = ''
File patterns or buffer names to match, determining which files or buffers trigger
glyph updates.
'';
};
};
}; };
}; };
} }