From d933b78dc8a8825b843791ff0c9a4a88f6ce4552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20=C5=98=C3=ADha?= <43958476+anriha@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:42:12 +0200 Subject: [PATCH] plugins/illuminate: init + test (#472) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * plugins/vim-illuminate: init + test * Fixed issue with empty test * Apply suggestions from code review Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> * Renamed from vilm-illuminate to illuminate * Update plugins/utils/illuminate.nix Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> --------- Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com> --- plugins/default.nix | 1 + plugins/utils/illuminate.nix | 144 ++++++++++++++++++ .../test-sources/plugins/utils/illuminate.nix | 34 +++++ 3 files changed, 179 insertions(+) create mode 100644 plugins/utils/illuminate.nix create mode 100644 tests/test-sources/plugins/utils/illuminate.nix diff --git a/plugins/default.nix b/plugins/default.nix index a439ba6f..dd0e1656 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -91,6 +91,7 @@ ./utils/floaterm.nix ./utils/goyo.nix ./utils/harpoon.nix + ./utils/illuminate.nix ./utils/indent-blankline.nix ./utils/intellitab.nix ./utils/lastplace.nix diff --git a/plugins/utils/illuminate.nix b/plugins/utils/illuminate.nix new file mode 100644 index 00000000..f8ee9e44 --- /dev/null +++ b/plugins/utils/illuminate.nix @@ -0,0 +1,144 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; let + cfg = config.plugins.illuminate; + helpers = import ../helpers.nix {inherit lib;}; + + mkListStr = helpers.defaultNullOpts.mkNullable (types.listOf types.str); + + commonOptions = with helpers.defaultNullOpts; { + providers = mkListStr ''["lsp" "treesitter" "regex"]'' '' + Provider used to get references in the buffer, ordered by priority. + ''; + + delay = mkInt 100 '' + Delay in milliseconds. + ''; + + modesDenylist = mkListStr "[]" '' + Modes to not illuminate, this overrides `modes_allowlist`. + See `:help mode()` for possible values. + ''; + + modesAllowlist = mkListStr "[]" '' + Modes to illuminate, this is overriden by `modes_denylist`. + See `:help mode()` for possible values. + ''; + + providersRegexSyntaxDenylist = mkListStr "[]" '' + Syntax to not illuminate, this overrides `providers_regex_syntax_allowlist`. + Only applies to the 'regex' provider. + Use `:echo synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')`. + ''; + + providersRegexSyntaxAllowlist = mkListStr "[]" '' + Syntax to illuminate, this is overriden by `providers_regex_syntax_denylist`. + Only applies to the 'regex' provider. + Use `:echo synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name')`. + ''; + + underCursor = mkBool true '' + Whether or not to illuminate under the cursor. + ''; + + largeFileCutoff = helpers.mkNullOrOption types.int '' + Number of lines at which to use `large_file_config`. + The `under_cursor` option is disabled when this cutoff is hit. + ''; + + minCountToHighlight = mkInt 1 '' + Minimum number of matches required to perform highlighting. + ''; + }; + + filetypeOptions = { + filetypesDenylist = mkListStr ''["dirvish" "fugitive"]'' '' + Filetypes to not illuminate, this overrides `filetypes_allowlist`. + ''; + + filetypesAllowlist = mkListStr "[]" '' + Filetypes to illuminate, this is overriden by `filetypes_denylist`. + ''; + }; +in { + options.plugins.illuminate = with helpers; + with defaultNullOpts; + helpers.extraOptionsOptions + // { + enable = mkEnableOption "vim-illuminate"; + + package = mkPackageOption "vim-illuminate" pkgs.vimPlugins.vim-illuminate; + + filetypeOverrides = mkOption { + type = types.listOf (types.submodule { + options = { + filetype = defaultNullOpts.mkStr "" '' + Filetype to override + ''; + + overrides = commonOptions; + }; + }); + description = '' + Filetype specific overrides. + ''; + default = []; + }; + + largeFileOverrides = mkOption { + type = types.submodule { + options = commonOptions // filetypeOptions; + }; + description = '' + Config to use for large files (based on large_file_cutoff). + Supports the same keys passed to .configure + If null, illuminate will be disabled for large files. + ''; + default = {}; + }; + } + // commonOptions + // filetypeOptions; + + config = let + filetypeSetupOptions = filetypeOptions: + with filetypeOptions; { + filetypes_denylist = filetypesDenylist; + filetypes_allowlist = filetypesAllowlist; + }; + commonSetupOptions = opts: + with opts; { + inherit providers; + inherit delay; + modes_denylist = modesDenylist; + modes_allowlist = modesAllowlist; + providers_regex_syntax_denylist = providersRegexSyntaxDenylist; + providers_regex_syntax_allowlist = providersRegexSyntaxAllowlist; + under_cursor = underCursor; + large_file_cutoff = largeFileCutoff; + min_count_to_highlight = minCountToHighlight; + }; + setupOptions = with cfg; + { + large_file_overrides = (commonSetupOptions largeFileOverrides) // (filetypeSetupOptions largeFileOverrides); + + filetype_overrides = let + override = attr: {${attr.filetype} = commonSetupOptions attr.overrides;}; + in + map override filetypeOverrides; + } + // (filetypeSetupOptions cfg) + // (commonSetupOptions cfg); + in + mkIf cfg.enable { + extraPlugins = [cfg.package]; + + extraConfigLua = '' + require("illuminate").configure(${helpers.toLuaObject setupOptions}) + ''; + }; +} diff --git a/tests/test-sources/plugins/utils/illuminate.nix b/tests/test-sources/plugins/utils/illuminate.nix new file mode 100644 index 00000000..becc24b7 --- /dev/null +++ b/tests/test-sources/plugins/utils/illuminate.nix @@ -0,0 +1,34 @@ +{ + empty = { + plugins.illuminate.enable = true; + }; + + example = { + plugins.illuminate = { + enable = true; + + delay = 50; + providers = ["lsp"]; + modesDenylist = ["n"]; + modesAllowlist = ["v"]; + underCursor = false; + largeFileCutoff = 10; + minCountToHighlight = 2; + filetypesDenylist = ["csharp"]; + filetypesAllowlist = ["python"]; + filetypeOverrides = [ + { + filetype = "c"; + overrides = { + delay = 10; + providers = ["treesitter"]; + }; + } + ]; + largeFileOverrides = { + delay = 20; + underCursor = true; + }; + }; + }; +}