1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-08 19:46:06 +01:00

plugins/gitlinker: migrate to mkNeovimPlugin

This commit is contained in:
Gaetan Lepage 2025-10-12 11:42:12 +02:00 committed by Gaétan Lepage
parent a830246ed9
commit d5f23804b4
3 changed files with 167 additions and 123 deletions

View file

@ -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 "<leader>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})
'';
};
}

View file

@ -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"
];
}
];
}

View file

@ -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 = "<leader>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 = "<leader>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";
};
};
};
};