Skip to content

Commit 9a93409

Browse files
committed
lsp/lightbulb: cleanup; modularize autocommand behaviour
1 parent 547cbd2 commit 9a93409

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

docs/release-notes/rl-0.8.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
your Editorconfig configuration, or use an autocommand to set indentation
3232
values for buffers with the Nix filetype.
3333

34+
- Add [](#opt-vim.lsp.lightbulb.autocmd.enable) for manually managing the
35+
previously managed lightbulb autocommand.
36+
- A warning will occur if [](#opt-vim.lsp.lightbulb.autocmd.enable) and
37+
`vim.lsp.lightbulb.setupOpts.autocmd.enabled` are both set at the same time.
38+
Pick only one.
39+
3440
[amadaluzia](https://github.com/amadaluzia):
3541

3642
[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim
@@ -59,7 +65,8 @@
5965
- Add `vim.snippets.luasnip.setupOpts`, which was previously missing.
6066
- Add `"prettierd"` as a formatter option in
6167
`vim.languages.markdown.format.type`.
62-
- Add the following plugins from [mini.nvim](https://github.com/echasnovski/mini.nvim)
68+
- Add the following plugins from
69+
[mini.nvim](https://github.com/echasnovski/mini.nvim)
6370
- `mini.ai`
6471
- `mini.align`
6572
- `mini.animate`
@@ -102,7 +109,8 @@
102109
- `mini.trailspace`
103110
- `mini.visits`
104111
- Add [fzf-lua](https://github.com/ibhagwan/fzf-lua) in `vim.fzf-lua`
105-
- Add [rainbow-delimiters](https://github.com/HiPhish/rainbow-delimiters.nvim) in `vim.visuals.rainbow-delimiters`
112+
- Add [rainbow-delimiters](https://github.com/HiPhish/rainbow-delimiters.nvim)
113+
in `vim.visuals.rainbow-delimiters`
106114
- Add options to define highlights under [](#opt-vim.highlight)
107115

108116
[kaktu5](https://github.com/kaktu5):
@@ -125,5 +133,5 @@
125133

126134
[ARCIII](https://github.com/ArmandoCIII):
127135

128-
- Add `vim.languages.zig.dap` support through pkgs.lldb dap adapter.
129-
Code Inspiration from `vim.languages.clang.dap` implementation.
136+
- Add `vim.languages.zig.dap` support through pkgs.lldb dap adapter. Code
137+
Inspiration from `vim.languages.clang.dap` implementation.

modules/plugins/lsp/lightbulb/config.nix

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
...
55
}: let
66
inherit (lib.modules) mkIf;
7+
inherit (lib.strings) optionalString;
78
inherit (lib.nvim.dag) entryAnywhere;
89
inherit (lib.nvim.lua) toLuaObject;
910

@@ -12,13 +13,29 @@ in {
1213
config = mkIf (cfg.enable && cfg.lightbulb.enable) {
1314
vim = {
1415
startPlugins = ["nvim-lightbulb"];
15-
1616
pluginRC.lightbulb = entryAnywhere ''
17-
vim.api.nvim_command('autocmd CursorHold,CursorHoldI * lua require\'nvim-lightbulb\'.update_lightbulb()')
18-
19-
-- Enable trouble diagnostics viewer
20-
require'nvim-lightbulb'.setup(${toLuaObject cfg.lightbulb.setupOpts})
17+
local nvim_lightbulb = require("nvim-lightbulb")
18+
nvim_lightbulb.setup(${toLuaObject cfg.lightbulb.setupOpts})
19+
${optionalString cfg.lightbulb.autocmd.enable ''
20+
vim.api.nvim_create_autocmd(${toLuaObject cfg.lightbulb.autocmd.events}, {
21+
pattern = ${toLuaObject cfg.lightbulb.autocmd.pattern},
22+
callback = function()
23+
nvim_lightbulb.update_lightbulb()
24+
end,
25+
})
26+
''}
2127
'';
2228
};
29+
30+
warnings = [
31+
# This could have been an assertion, but the chances of collision is very low and asserting here
32+
# might be too dramatic. Let's only warn the user, *in case* this occurs and is not intended. No
33+
# error will be thrown if 'lightbulb.setupOpts.autocmd.enable' has not been set by the user.
34+
(mkIf (cfg.lightbulb.autocmd.enable -> (cfg.lightbulb.setupOpts.autocmd.enabled or false)) ''
35+
Both 'vim.lsp.lightbulb.autocmd.enable' and 'vim.lsp.lightbulb.setupOpts.autocmd.enable' are set
36+
simultaneously. This might have performance implications due to frequent updates. Please set only
37+
one option to handle nvim-lightbulb autocmd.
38+
'')
39+
];
2340
};
2441
}
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
{lib, ...}: let
2-
inherit (lib.options) mkEnableOption;
3-
inherit (lib.nvim.types) mkPluginSetupOption;
2+
inherit (lib.options) mkOption mkEnableOption;
3+
inherit (lib.types) listOf str either;
4+
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
45
in {
56
options.vim.lsp = {
67
lightbulb = {
78
enable = mkEnableOption "Lightbulb for code actions. Requires an emoji font";
89
setupOpts = mkPluginSetupOption "nvim-lightbulb" {};
10+
autocmd = {
11+
enable = mkEnableOption "updating lightbulb glyph automatically" // {default = true;};
12+
events = mkOption {
13+
type = listOf str;
14+
default = ["CursorHold" "CursorHoldI"];
15+
description = "Events on which to update nvim-lightbulb glyphs";
16+
};
17+
18+
pattern = mkOption {
19+
type = either str luaInline;
20+
default = "*";
21+
description = ''
22+
File patterns or buffer names to match, determining which files or buffers trigger
23+
glyph updates.
24+
'';
25+
};
26+
};
927
};
1028
};
1129
}

0 commit comments

Comments
 (0)