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:
parent
a830246ed9
commit
d5f23804b4
3 changed files with 167 additions and 123 deletions
|
|
@ -1,109 +1,24 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
helpers,
|
name = "gitlinker";
|
||||||
config,
|
package = "gitlinker-nvim";
|
||||||
pkgs,
|
description = "A simple popup display that provides a breadcrumbs feature using an LSP server.";
|
||||||
...
|
maintainers = [ ];
|
||||||
}:
|
|
||||||
with lib;
|
|
||||||
{
|
|
||||||
options.plugins.gitlinker = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
|
||||||
enable = mkEnableOption "gitlinker.nvim";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "gitlinker.nvim" {
|
# TODO: introduced 2025-10-12: remove after 26.05
|
||||||
default = [
|
inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings imports;
|
||||||
"vimPlugins"
|
|
||||||
"gitlinker-nvim"
|
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})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
105
plugins/by-name/gitlinker/deprecations.nix
Normal file
105
plugins/by-name/gitlinker/deprecations.nix
Normal 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"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,30 +1,54 @@
|
||||||
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
empty = {
|
empty = {
|
||||||
plugins.gitlinker.enable = true;
|
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 = {
|
defaults = {
|
||||||
plugins.gitlinker = {
|
plugins.gitlinker = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
remote = null;
|
settings = {
|
||||||
addCurrentLineOnNormalMode = true;
|
opts = {
|
||||||
actionCallback = "copy_to_clipboard";
|
remote = null;
|
||||||
printUrl = true;
|
add_current_line_on_normal_mode = true;
|
||||||
mappings = "<leader>gy";
|
action_callback = lib.nixvim.mkRaw "require('gitlinker.actions').copy_to_clipboard";
|
||||||
|
print_url = true;
|
||||||
callbacks = {
|
mappings = "<leader>gy";
|
||||||
"github.com" = "get_github_type_url";
|
};
|
||||||
"gitlab.com" = "get_gitlab_type_url";
|
callbacks = {
|
||||||
"try.gitea.io" = "get_gitea_type_url";
|
"github.com" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_github_type_url";
|
||||||
"codeberg.org" = "get_gitea_type_url";
|
"gitlab.com" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitlab_type_url";
|
||||||
"bitbucket.org" = "get_bitbucket_type_url";
|
"try.gitea.io" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitea_type_url";
|
||||||
"try.gogs.io" = "get_gogs_type_url";
|
"codeberg.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gitea_type_url";
|
||||||
"git.sr.ht" = "get_srht_type_url";
|
"bitbucket.org" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_bitbucket_type_url";
|
||||||
"git.launchpad.net" = "get_launchpad_type_url";
|
"try.gogs.io" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_gogs_type_url";
|
||||||
"repo.or.cz" = "get_repoorcz_type_url";
|
"git.sr.ht" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_srht_type_url";
|
||||||
"git.kernel.org" = "get_cgit_type_url";
|
"git.launchpad.net" = lib.nixvim.mkRaw "require('gitlinker.hosts').get_launchpad_type_url";
|
||||||
"git.savannah.gnu.org" = "get_cgit_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";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue