From c97f9dab2cbe6e643ef50ace97c1843729004d7b Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 19 Jan 2025 20:26:52 +0300 Subject: [PATCH] lsp/lightbulb: cleanup; modularize autocommand behaviour --- docs/release-notes/rl-0.8.md | 6 ++++- modules/plugins/lsp/lightbulb/config.nix | 26 +++++++++++++++++---- modules/plugins/lsp/lightbulb/lightbulb.nix | 11 ++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 42927baf..3d7eebd3 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -31,6 +31,9 @@ your Editorconfig configuration, or use an autocommand to set indentation values for buffers with the Nix filetype. +- Add [](#opt-vim.lsp.lightbulb.autocmd.enable) for manually managing the + previously managed lightbulb autocommand. + [amadaluzia](https://github.com/amadaluzia): [haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim @@ -59,7 +62,8 @@ - Add `vim.snippets.luasnip.setupOpts`, which was previously missing. - Add `"prettierd"` as a formatter option in `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.align` - `mini.animate` diff --git a/modules/plugins/lsp/lightbulb/config.nix b/modules/plugins/lsp/lightbulb/config.nix index f17b8ad9..2c4afa67 100644 --- a/modules/plugins/lsp/lightbulb/config.nix +++ b/modules/plugins/lsp/lightbulb/config.nix @@ -4,6 +4,7 @@ ... }: let inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; @@ -12,13 +13,28 @@ in { config = mkIf (cfg.enable && cfg.lightbulb.enable) { vim = { startPlugins = ["nvim-lightbulb"]; - pluginRC.lightbulb = entryAnywhere '' - vim.api.nvim_command('autocmd CursorHold,CursorHoldI * lua require\'nvim-lightbulb\'.update_lightbulb()') - - -- Enable trouble diagnostics viewer - require'nvim-lightbulb'.setup(${toLuaObject cfg.lightbulb.setupOpts}) + local nvim-lightbulb = require('nvim-lightbulb') + nvim-lightbulb.setup(${toLuaObject cfg.lightbulb.setupOpts}) + ${optionalString cfg.lightbulb.autocmd.enable '' + vim.api.nvim_create_autocmd(${toLuaObject cfg.lightbulb.autocmd.events}, { + 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. + (optionalString (cfg.lightbulb.setupOpts.autocmd.enable && cfg.lightbulb.autocmd.enable) '' + 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. + '') + ]; }; } diff --git a/modules/plugins/lsp/lightbulb/lightbulb.nix b/modules/plugins/lsp/lightbulb/lightbulb.nix index 4341cac6..720d2d39 100644 --- a/modules/plugins/lsp/lightbulb/lightbulb.nix +++ b/modules/plugins/lsp/lightbulb/lightbulb.nix @@ -1,11 +1,20 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption; + inherit (lib.options) mkOption mkEnableOption; + inherit (lib.types) listOf str; inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.lsp = { lightbulb = { enable = mkEnableOption "Lightbulb for code actions. Requires an emoji font"; setupOpts = mkPluginSetupOption "nvim-lightbulb" {}; + autocmd = { + enable = mkEnableOption "updating lightbulb glyph automatically"; + events = mkOption { + type = listOf str; + default = ["CursorHold" "CursorHoldI"]; + description = "Events on which to update nvim-lightbulb glyphs"; + }; + }; }; }; }