mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
plugins/cmp-git: general cleanup of options
- Replace all pre-formatted plugin defaults - Move several options to `strLuaFn` - Refactored "action" options to use a `mkAction` helper - Fix some incorrect examples/tests - Remove undocumented `filter_fn` from settings example
This commit is contained in:
parent
130a66bce7
commit
7087b6014d
2 changed files with 120 additions and 160 deletions
|
@ -7,18 +7,26 @@
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.plugins.cmp-git;
|
cfg = config.plugins.cmp-git;
|
||||||
|
|
||||||
|
mkAction =
|
||||||
|
action: target:
|
||||||
|
helpers.defaultNullOpts.mkLuaFn "require('cmp_git.${action}').git.${target}" ''
|
||||||
|
Function used to ${action} the ${replaceStrings [ "_" ] [ " " ] target}.
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.plugins.cmp-git.settings = helpers.neovim-plugin.mkSettingsOption {
|
options.plugins.cmp-git.settings = helpers.neovim-plugin.mkSettingsOption {
|
||||||
pluginName = "cmp_git";
|
pluginName = "cmp_git";
|
||||||
options = {
|
options = {
|
||||||
filetypes = helpers.defaultNullOpts.mkListOf types.str ''["gitcommit" "octo"]'' ''
|
filetypes = helpers.defaultNullOpts.mkListOf types.str [
|
||||||
Filetypes for which to trigger.
|
"gitcommit"
|
||||||
'';
|
"octo"
|
||||||
|
] "Filetypes for which to trigger.";
|
||||||
|
|
||||||
remotes = helpers.defaultNullOpts.mkListOf types.str ''["upstream" "origin"]'' ''
|
remotes = helpers.defaultNullOpts.mkListOf types.str [
|
||||||
List of git remotes.
|
"upstream"
|
||||||
'';
|
"origin"
|
||||||
|
] "List of git remotes.";
|
||||||
|
|
||||||
enableRemoteUrlRewrites = helpers.defaultNullOpts.mkBool false ''
|
enableRemoteUrlRewrites = helpers.defaultNullOpts.mkBool false ''
|
||||||
Whether to enable remote URL rewrites.
|
Whether to enable remote URL rewrites.
|
||||||
|
@ -30,27 +38,24 @@ in
|
||||||
Max number of git commits to fetch.
|
Max number of git commits to fetch.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "commits";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "commits";
|
||||||
''{__raw = "require('cmp_git.sort').git.commits";}''
|
|
||||||
"Function used to sort the commits.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').git.commits";}''
|
|
||||||
"Function used to format the commits.";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
github = {
|
github = {
|
||||||
hosts = helpers.defaultNullOpts.mkListOf types.str "[]" ''
|
hosts = helpers.defaultNullOpts.mkListOf types.str [ ] ''
|
||||||
List of private instances of github.
|
List of private instances of github.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
issues = {
|
issues = {
|
||||||
fields =
|
fields = helpers.defaultNullOpts.mkListOf types.str [
|
||||||
helpers.defaultNullOpts.mkListOf types.str ''["title" "number" "body" "updatedAt" "state"]''
|
"title"
|
||||||
"The fields used for issues.";
|
"number"
|
||||||
|
"body"
|
||||||
|
"updatedAt"
|
||||||
|
"state"
|
||||||
|
] "The fields used for issues.";
|
||||||
|
|
||||||
filter = helpers.defaultNullOpts.mkStr "all" ''
|
filter = helpers.defaultNullOpts.mkStr "all" ''
|
||||||
The filter to use when fetching issues.
|
The filter to use when fetching issues.
|
||||||
|
@ -64,15 +69,8 @@ in
|
||||||
Which issues to fetch (`"open"`, `"closed"` or `"all"`).
|
Which issues to fetch (`"open"`, `"closed"` or `"all"`).
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "issues";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "issues";
|
||||||
''{__raw = "require('cmp_git.sort').github.issues";}''
|
|
||||||
"Function used to sort the issues.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').github.issues";}''
|
|
||||||
"Function used to format the issues.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mentions = {
|
mentions = {
|
||||||
|
@ -80,21 +78,18 @@ in
|
||||||
Max number of mentions to fetch.
|
Max number of mentions to fetch.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "mentions";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "mentions";
|
||||||
''{__raw = "require('cmp_git.sort').github.mentions";}''
|
|
||||||
"Function used to sort the mentions.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').github.mentions";}''
|
|
||||||
"Function used to format the mentions.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pull_requests = {
|
pull_requests = {
|
||||||
fields =
|
fields = helpers.defaultNullOpts.mkListOf types.str [
|
||||||
helpers.defaultNullOpts.mkListOf types.str ''["title" "number" "body" "updatedAt" "state"]''
|
"title"
|
||||||
"The fields used for pull requests.";
|
"number"
|
||||||
|
"body"
|
||||||
|
"updatedAt"
|
||||||
|
"state"
|
||||||
|
] "The fields used for pull requests.";
|
||||||
|
|
||||||
limit = helpers.defaultNullOpts.mkUnsignedInt 100 ''
|
limit = helpers.defaultNullOpts.mkUnsignedInt 100 ''
|
||||||
Max number of pull requests to fetch.
|
Max number of pull requests to fetch.
|
||||||
|
@ -104,20 +99,13 @@ in
|
||||||
Which issues to fetch (`"open"`, `"closed"`, `"merged"` or `"all"`).
|
Which issues to fetch (`"open"`, `"closed"`, `"merged"` or `"all"`).
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "pull_requests";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "pull_requests";
|
||||||
''{__raw = "require('cmp_git.sort').github.pull_requests";}''
|
|
||||||
"Function used to sort the pull requests.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').github.pull_requests";}''
|
|
||||||
"Function used to format the pull requests.";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
gitlab = {
|
gitlab = {
|
||||||
hosts = helpers.defaultNullOpts.mkListOf types.str "[]" ''
|
hosts = helpers.defaultNullOpts.mkListOf types.str [ ] ''
|
||||||
List of private instances of gitlab.
|
List of private instances of gitlab.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -130,15 +118,8 @@ in
|
||||||
Which issues to fetch (`"open"`, `"closed"` or `"all"`).
|
Which issues to fetch (`"open"`, `"closed"` or `"all"`).
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "issues";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "issues";
|
||||||
''{__raw = "require('cmp_git.sort').gitlab.issues";}''
|
|
||||||
"Function used to sort the issues.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').gitlab.issues";}''
|
|
||||||
"Function used to format the issues.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mentions = {
|
mentions = {
|
||||||
|
@ -146,15 +127,8 @@ in
|
||||||
Max number of mentions to fetch.
|
Max number of mentions to fetch.
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "mentions";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "mentions";
|
||||||
''{__raw = "require('cmp_git.sort').gitlab.mentions";}''
|
|
||||||
"Function used to sort the mentions.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').gitlab.mentions";}''
|
|
||||||
"Function used to format the mentions.";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
merge_requests = {
|
merge_requests = {
|
||||||
|
@ -166,15 +140,8 @@ in
|
||||||
Which issues to fetch (`"open"`, `"closed"`, `"locked"` or `"merged"`).
|
Which issues to fetch (`"open"`, `"closed"`, `"locked"` or `"merged"`).
|
||||||
'';
|
'';
|
||||||
|
|
||||||
sort_by =
|
sort_by = mkAction "sort" "merge_requests";
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
format = mkAction "format" "merge_requests";
|
||||||
''{__raw = "require('cmp_git.sort').gitlab.merge_requests";}''
|
|
||||||
"Function used to sort the merge requests.";
|
|
||||||
|
|
||||||
format =
|
|
||||||
helpers.defaultNullOpts.mkNullable types.anything
|
|
||||||
''{__raw = "require('cmp_git.format').gitlab.merge_requests";}''
|
|
||||||
"Function used to format the merge requests.";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,64 +176,62 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
''
|
[
|
||||||
[
|
{
|
||||||
{
|
debug_name = "git_commits";
|
||||||
debug_name = "git_commits";
|
trigger_character = ":";
|
||||||
trigger_character = ":";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.git:get_commits(callback, params, trigger_char)
|
||||||
return sources.git:get_commits(callback, params, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
{
|
||||||
{
|
debug_name = "gitlab_issues";
|
||||||
debug_name = "gitlab_issues";
|
trigger_character = "#";
|
||||||
trigger_character = "#";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.gitlab:get_issues(callback, git_info, trigger_char)
|
||||||
return sources.gitlab:get_issues(callback, git_info, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
{
|
||||||
{
|
debug_name = "gitlab_mentions";
|
||||||
debug_name = "gitlab_mentions";
|
trigger_character = "@";
|
||||||
trigger_character = "@";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.gitlab:get_mentions(callback, git_info, trigger_char)
|
||||||
return sources.gitlab:get_mentions(callback, git_info, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
{
|
||||||
{
|
debug_name = "gitlab_mrs";
|
||||||
debug_name = "gitlab_mrs";
|
trigger_character = "!";
|
||||||
trigger_character = "!";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.gitlab:get_merge_requests(callback, git_info, trigger_char)
|
||||||
return sources.gitlab:get_merge_requests(callback, git_info, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
{
|
||||||
{
|
debug_name = "github_issues_and_pr";
|
||||||
debug_name = "github_issues_and_pr";
|
trigger_character = "#";
|
||||||
trigger_character = "#";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.github:get_issues_and_prs(callback, git_info, trigger_char)
|
||||||
return sources.github:get_issues_and_prs(callback, git_info, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
{
|
||||||
{
|
debug_name = "github_mentions";
|
||||||
debug_name = "github_mentions";
|
trigger_character = "@";
|
||||||
trigger_character = "@";
|
action = ''
|
||||||
action = \'\'
|
function(sources, trigger_char, callback, params, git_info)
|
||||||
function(sources, trigger_char, callback, params, git_info)
|
return sources.github:get_mentions(callback, git_info, trigger_char)
|
||||||
return sources.github:get_mentions(callback, git_info, trigger_char)
|
end
|
||||||
end
|
'';
|
||||||
\'\';
|
}
|
||||||
}
|
]
|
||||||
]
|
|
||||||
''
|
|
||||||
''
|
''
|
||||||
If you want specific behaviour for a trigger or new behaviour for a trigger, you need to
|
If you want specific behaviour for a trigger or new behaviour for a trigger, you need to
|
||||||
add an entry in the `trigger_actions` list of the config.
|
add an entry in the `trigger_actions` list of the config.
|
||||||
|
@ -284,7 +249,7 @@ in
|
||||||
filter = "all";
|
filter = "all";
|
||||||
limit = 250;
|
limit = 250;
|
||||||
state = "all";
|
state = "all";
|
||||||
format.label.__raw = ''
|
format = ''
|
||||||
function(_, issue)
|
function(_, issue)
|
||||||
local icon = ({
|
local icon = ({
|
||||||
open = '',
|
open = '',
|
||||||
|
@ -293,7 +258,7 @@ in
|
||||||
return string.format('%s #%d: %s', icon, issue.number, issue.title)
|
return string.format('%s #%d: %s', icon, issue.number, issue.title)
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
sort_by.__raw = ''
|
sort_by = ''
|
||||||
function(issue)
|
function(issue)
|
||||||
local kind_rank = issue.pull_request and 1 or 0
|
local kind_rank = issue.pull_request and 1 or 0
|
||||||
local state_rank = issue.state == 'open' and 0 or 1
|
local state_rank = issue.state == 'open' and 0 or 1
|
||||||
|
@ -301,11 +266,6 @@ in
|
||||||
return string.format('%d%d%010d', kind_rank, state_rank, age)
|
return string.format('%d%d%010d', kind_rank, state_rank, age)
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
filter_fn.__raw = ''
|
|
||||||
function(trigger_char, issue)
|
|
||||||
return string.format('%s %s %s', trigger_char, issue.number, issue.title)
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
trigger_actions = [
|
trigger_actions = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
git = {
|
git = {
|
||||||
commits = {
|
commits = {
|
||||||
limit = 100;
|
limit = 100;
|
||||||
sort_by.__raw = "require('cmp_git.sort').git.commits";
|
sort_by = "require('cmp_git.sort').git.commits";
|
||||||
format.__raw = "require('cmp_git.format').git.commits";
|
format = "require('cmp_git.format').git.commits";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
github = {
|
github = {
|
||||||
|
@ -36,13 +36,13 @@
|
||||||
filter = "all";
|
filter = "all";
|
||||||
limit = 100;
|
limit = 100;
|
||||||
state = "open";
|
state = "open";
|
||||||
sort_by.__raw = "require('cmp_git.sort').github.issues";
|
sort_by = "require('cmp_git.sort').github.issues";
|
||||||
format.__raw = "require('cmp_git.format').github.issues";
|
format = "require('cmp_git.format').github.issues";
|
||||||
};
|
};
|
||||||
mentions = {
|
mentions = {
|
||||||
limit = 100;
|
limit = 100;
|
||||||
sort_by.__raw = "require('cmp_git.sort').github.mentions";
|
sort_by = "require('cmp_git.sort').github.mentions";
|
||||||
format.__raw = "require('cmp_git.format').github.mentions";
|
format = "require('cmp_git.format').github.mentions";
|
||||||
};
|
};
|
||||||
pull_requests = {
|
pull_requests = {
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -54,8 +54,8 @@
|
||||||
];
|
];
|
||||||
limit = 100;
|
limit = 100;
|
||||||
state = "open";
|
state = "open";
|
||||||
sort_by.__raw = "require('cmp_git.sort').github.pull_requests";
|
sort_by = "require('cmp_git.sort').github.pull_requests";
|
||||||
format.__raw = "require('cmp_git.format').github.pull_requests";
|
format = "require('cmp_git.format').github.pull_requests";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
gitlab = {
|
gitlab = {
|
||||||
|
@ -63,19 +63,19 @@
|
||||||
issues = {
|
issues = {
|
||||||
limit = 100;
|
limit = 100;
|
||||||
state = "opened";
|
state = "opened";
|
||||||
sort_by.__raw = "require('cmp_git.sort').gitlab.pull_requests";
|
sort_by = "require('cmp_git.sort').gitlab.pull_requests";
|
||||||
format.__raw = "require('cmp_git.format').gitlab.pull_requests";
|
format = "require('cmp_git.format').gitlab.pull_requests";
|
||||||
};
|
};
|
||||||
mentions = {
|
mentions = {
|
||||||
limit = 100;
|
limit = 100;
|
||||||
sort_by.__raw = "require('cmp_git.sort').gitlab.mentions";
|
sort_by = "require('cmp_git.sort').gitlab.mentions";
|
||||||
format.__raw = "require('cmp_git.format').gitlab.mentions";
|
format = "require('cmp_git.format').gitlab.mentions";
|
||||||
};
|
};
|
||||||
merge_requests = {
|
merge_requests = {
|
||||||
limit = 100;
|
limit = 100;
|
||||||
state = "opened";
|
state = "opened";
|
||||||
sort_by.__raw = "require('cmp_git.sort').gitlab.merge_requests";
|
sort_by = "require('cmp_git.sort').gitlab.merge_requests";
|
||||||
format.__raw = "require('cmp_git.format').gitlab.merge_requests";
|
format = "require('cmp_git.format').gitlab.merge_requests";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
trigger_actions = [
|
trigger_actions = [
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
filter = "all";
|
filter = "all";
|
||||||
limit = 250;
|
limit = 250;
|
||||||
state = "all";
|
state = "all";
|
||||||
format.label.__raw = ''
|
format = ''
|
||||||
function(_, issue)
|
function(_, issue)
|
||||||
local icon = ({
|
local icon = ({
|
||||||
open = '',
|
open = '',
|
||||||
|
@ -165,7 +165,7 @@
|
||||||
return string.format('%s #%d: %s', icon, issue.number, issue.title)
|
return string.format('%s #%d: %s', icon, issue.number, issue.title)
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
sort_by.__raw = ''
|
sort_by = ''
|
||||||
function(issue)
|
function(issue)
|
||||||
local kind_rank = issue.pull_request and 1 or 0
|
local kind_rank = issue.pull_request and 1 or 0
|
||||||
local state_rank = issue.state == 'open' and 0 or 1
|
local state_rank = issue.state == 'open' and 0 or 1
|
||||||
|
@ -191,7 +191,7 @@
|
||||||
pull_requests = {
|
pull_requests = {
|
||||||
limit = 250;
|
limit = 250;
|
||||||
state = "all";
|
state = "all";
|
||||||
format.label.__raw = ''
|
format = ''
|
||||||
function(_, pr)
|
function(_, pr)
|
||||||
local icon = ({
|
local icon = ({
|
||||||
open = '',
|
open = '',
|
||||||
|
@ -200,7 +200,7 @@
|
||||||
return string.format('%s #%d: %s', icon, pr.number, pr.title)
|
return string.format('%s #%d: %s', icon, pr.number, pr.title)
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
sort_by.__raw = ''
|
sort_by = ''
|
||||||
function(pr)
|
function(pr)
|
||||||
local state_rank = pr.state == 'open' and 0 or 1
|
local state_rank = pr.state == 'open' and 0 or 1
|
||||||
local age = os.difftime(os.time(), require('cmp_git.utils').parse_github_date(pr.updatedAt))
|
local age = os.difftime(os.time(), require('cmp_git.utils').parse_github_date(pr.updatedAt))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue