Skip to content

Commit 04e5af1

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

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

docs/release-notes/rl-0.8.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
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+
3437
[amadaluzia](https://github.com/amadaluzia):
3538

3639
[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim
@@ -59,7 +62,8 @@
5962
- Add `vim.snippets.luasnip.setupOpts`, which was previously missing.
6063
- Add `"prettierd"` as a formatter option in
6164
`vim.languages.markdown.format.type`.
62-
- Add the following plugins from [mini.nvim](https://github.com/echasnovski/mini.nvim)
65+
- Add the following plugins from
66+
[mini.nvim](https://github.com/echasnovski/mini.nvim)
6367
- `mini.ai`
6468
- `mini.align`
6569
- `mini.animate`

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+
(optionalString (cfg.lightbulb.autocmd.enable -> (cfg.lightbulb.setupOpts.autocmd.enable 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)