From d5f23804b46f5077fe9c75a119fa87b68b778c0f Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 12 Oct 2025 11:42:12 +0200 Subject: [PATCH] plugins/gitlinker: migrate to mkNeovimPlugin --- plugins/by-name/gitlinker/default.nix | 125 +++--------------- plugins/by-name/gitlinker/deprecations.nix | 105 +++++++++++++++ .../plugins/by-name/gitlinker/default.nix | 60 ++++++--- 3 files changed, 167 insertions(+), 123 deletions(-) create mode 100644 plugins/by-name/gitlinker/deprecations.nix diff --git a/plugins/by-name/gitlinker/default.nix b/plugins/by-name/gitlinker/default.nix index 63765c4a..aa2b5980 100644 --- a/plugins/by-name/gitlinker/default.nix +++ b/plugins/by-name/gitlinker/default.nix @@ -1,109 +1,24 @@ -{ - lib, - helpers, - config, - pkgs, - ... -}: -with lib; -{ - options.plugins.gitlinker = lib.nixvim.plugins.neovim.extraOptionsOptions // { - enable = mkEnableOption "gitlinker.nvim"; +{ lib, ... }: +lib.nixvim.plugins.mkNeovimPlugin { + name = "gitlinker"; + package = "gitlinker-nvim"; + description = "A simple popup display that provides a breadcrumbs feature using an LSP server."; + maintainers = [ ]; - package = lib.mkPackageOption pkgs "gitlinker.nvim" { - default = [ - "vimPlugins" - "gitlinker-nvim" - ]; + # TODO: introduced 2025-10-12: remove after 26.05 + inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings imports; + + settingsExample = { + opts = { + action_callback = lib.nixvim.nestedLiteralLua '' + function(url) + -- yank to unnamed register + vim.api.nvim_command("let @\" = '" .. url .. "'") + -- copy to the system clipboard using OSC52 + vim.fn.OSCYankString(url) + end + ''; + print_url = false; }; - - remote = helpers.mkNullOrOption types.str "Force the use of a specific remote."; - - addCurrentLineOnNormalMode = helpers.defaultNullOpts.mkBool true '' - Adds current line nr in the url for normal mode. - ''; - - actionCallback = - helpers.defaultNullOpts.mkNullable (with types; either str rawLua) "copy_to_clipboard" - '' - Callback for what to do with the url. - - Can be - - the name of a built-in callback. Example: `actionCallback = "copy_to_clipboard";` is - setting - ```lua - require('gitlinker.actions').copy_to_clipboard - ``` - in lua. - - Raw lua code `actionCallback.__raw = "function() ... end";`. - ''; - - printUrl = helpers.defaultNullOpts.mkBool true "Print the url after performing the action."; - - mappings = helpers.defaultNullOpts.mkStr "gy" "Mapping to call url generation."; - - callbacks = - helpers.defaultNullOpts.mkAttrsOf types.str - { - "github.com" = "get_github_type_url"; - "gitlab.com" = "get_gitlab_type_url"; - "try.gitea.io" = "get_gitea_type_url"; - "codeberg.org" = "get_gitea_type_url"; - "bitbucket.org" = "get_bitbucket_type_url"; - "try.gogs.io" = "get_gogs_type_url"; - "git.sr.ht" = "get_srht_type_url"; - "git.launchpad.net" = "get_launchpad_type_url"; - "repo.or.cz" = "get_repoorcz_type_url"; - "git.kernel.org" = "get_cgit_type_url"; - "git.savannah.gnu.org" = "get_cgit_type_url"; - } - '' - Each key can be - - the name of a built-in callback. Example: `"get_gitlab_type_url";` is setting - ```lua - require('gitlinker.hosts').get_gitlab_type_url - ``` - in lua. - - Raw lua code `"github.com".__raw = "function(url_data) ... end";`. - - Learn more by reading `:h gitinker-callbacks`. - ''; }; - - config = - let - cfg = config.plugins.gitlinker; - in - mkIf cfg.enable { - extraPlugins = [ cfg.package ]; - - extraConfigLua = - let - setupOptions = - with cfg; - { - opts = { - inherit remote; - add_current_line_on_normal_mode = addCurrentLineOnNormalMode; - action_callback = - if isString actionCallback then - helpers.mkRaw "require('gitlinker.actions').${actionCallback}" - else - actionCallback; - print_url = printUrl; - inherit mappings; - }; - callbacks = helpers.ifNonNull' callbacks ( - mapAttrs ( - source: callback: - if isString callback then helpers.mkRaw "require('gitlinker.hosts').${callback}" else callback - ) callbacks - ); - } - // cfg.extraOptions; - in - '' - require('gitlinker').setup(${lib.nixvim.toLuaObject setupOptions}) - ''; - }; } diff --git a/plugins/by-name/gitlinker/deprecations.nix b/plugins/by-name/gitlinker/deprecations.nix new file mode 100644 index 00000000..17af60dd --- /dev/null +++ b/plugins/by-name/gitlinker/deprecations.nix @@ -0,0 +1,105 @@ +lib: { + imports = + let + basePluginPath = [ + "plugins" + "gitlinker" + ]; + in + [ + ( + let + oldPath = basePluginPath ++ [ "actionCallback" ]; + in + lib.mkChangedOptionModule oldPath + ( + basePluginPath + ++ [ + "settings" + "opts" + "action_callback" + ] + ) + ( + config: + let + oldValue = lib.getAttrFromPath oldPath config; + in + if lib.isString oldValue then + let + newString = "require('gitlinker.actions').${oldValue}"; + in + lib.warn '' + WARNING: the `plugins.gitlinker.settings.opts.action_callback` does not automatically process the provided input. + You will need to explicitly write `action_callback.__raw = "${newString}"`. + '' lib.nixvim.mkRaw newString + else + oldValue + ) + ) + ( + let + oldPath = basePluginPath ++ [ "callbacks" ]; + in + lib.mkChangedOptionModule oldPath + ( + basePluginPath + ++ [ + "settings" + "callbacks" + ] + ) + ( + config: + let + oldValue = lib.getAttrFromPath oldPath config; + in + lib.mapAttrs ( + source: callback: + if lib.isString callback then + let + newString = "require('gitlinker.hosts').${callback}"; + in + lib.warn '' + WARNING: the `plugins.gitlinker.settings.opts.action_callback` does not automatically process the provided input. + You will need to explicitly write `${callback}.__raw = "${newString}"`. + '' lib.nixvim.mkRaw newString + else + callback + ) oldValue + ) + ) + ]; + deprecateExtraOptions = true; + + optionsRenamedToSettings = [ + { + old = "remote"; + new = [ + "opts" + "remote" + ]; + } + { + old = "addCurrentLineOnNormalMode"; + new = [ + "opts" + "add_current_line_on_normal_mode" + ]; + } + { + old = "printUrl"; + new = [ + "opts" + "print_url" + ]; + } + { + old = "mappings"; + new = [ + "opts" + "mappings" + ]; + } + ]; +} diff --git a/tests/test-sources/plugins/by-name/gitlinker/default.nix b/tests/test-sources/plugins/by-name/gitlinker/default.nix index b089bffe..0524c5ce 100644 --- a/tests/test-sources/plugins/by-name/gitlinker/default.nix +++ b/tests/test-sources/plugins/by-name/gitlinker/default.nix @@ -1,30 +1,54 @@ +{ lib, ... }: { empty = { plugins.gitlinker.enable = true; }; + example = { + plugins.gitlinker = { + enable = true; + + settings = { + opts = { + action_callback = lib.nixvim.mkRaw '' + function(url) + -- yank to unnamed register + vim.api.nvim_command("let @\" = '" .. url .. "'") + -- copy to the system clipboard using OSC52 + vim.fn.OSCYankString(url) + end + ''; + print_url = false; + }; + }; + }; + }; + defaults = { plugins.gitlinker = { enable = true; - remote = null; - addCurrentLineOnNormalMode = true; - actionCallback = "copy_to_clipboard"; - printUrl = true; - mappings = "gy"; - - callbacks = { - "github.com" = "get_github_type_url"; - "gitlab.com" = "get_gitlab_type_url"; - "try.gitea.io" = "get_gitea_type_url"; - "codeberg.org" = "get_gitea_type_url"; - "bitbucket.org" = "get_bitbucket_type_url"; - "try.gogs.io" = "get_gogs_type_url"; - "git.sr.ht" = "get_srht_type_url"; - "git.launchpad.net" = "get_launchpad_type_url"; - "repo.or.cz" = "get_repoorcz_type_url"; - "git.kernel.org" = "get_cgit_type_url"; - "git.savannah.gnu.org" = "get_cgit_type_url"; + settings = { + opts = { + remote = null; + add_current_line_on_normal_mode = true; + action_callback = lib.nixvim.mkRaw "require('gitlinker.actions').copy_to_clipboard"; + print_url = true; + mappings = "gy"; + }; + callbacks = { + "github.com" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_github_type_url"; + "gitlab.com" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitlab_type_url"; + "try.gitea.io" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitea_type_url"; + "codeberg.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitea_type_url"; + "bitbucket.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_bitbucket_type_url"; + "try.gogs.io" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gogs_type_url"; + "git.sr.ht" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_srht_type_url"; + "git.launchpad.net" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_launchpad_type_url"; + "repo.or.cz" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_repoorcz_type_url"; + "git.kernel.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_cgit_type_url"; + "git.savannah.gnu.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_cgit_type_url"; + }; }; }; };