mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-28 19:40:06 +02:00
plugins/completion: move to by-name
- Move nvim-cmp to plugins/cmp - Move other completion plugins to plugins/by-name
This commit is contained in:
parent
3211a63306
commit
ad85cd760e
36 changed files with 2 additions and 9 deletions
39
tests/test-sources/plugins/cmp/all-sources.nix
Normal file
39
tests/test-sources/plugins/cmp/all-sources.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
all-sources =
|
||||
{ config, ... }:
|
||||
{
|
||||
plugins = {
|
||||
copilot-lua = {
|
||||
enable = true;
|
||||
|
||||
panel.enabled = false;
|
||||
suggestion.enabled = false;
|
||||
};
|
||||
|
||||
cmp = {
|
||||
enable = true;
|
||||
settings.sources =
|
||||
with pkgs.lib;
|
||||
let
|
||||
disabledSources = [
|
||||
# We do not provide the required HF_API_KEY environment variable.
|
||||
"cmp_ai"
|
||||
# Triggers the warning complaining about treesitter highlighting being disabled
|
||||
"otter"
|
||||
] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine";
|
||||
in
|
||||
pipe config.cmpSourcePlugins [
|
||||
# All known source names
|
||||
attrNames
|
||||
# Filter out disabled sources
|
||||
(filter (name: !(elem name disabledSources)))
|
||||
# Convert names to source attributes
|
||||
(map (name: {
|
||||
inherit name;
|
||||
}))
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
37
tests/test-sources/plugins/cmp/cmp-ai.nix
Normal file
37
tests/test-sources/plugins/cmp/cmp-ai.nix
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
empty = {
|
||||
# We do not provide the required HF_API_KEY environment variable.
|
||||
test.runNvim = false;
|
||||
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "cmp_ai"; } ];
|
||||
};
|
||||
};
|
||||
|
||||
example = {
|
||||
# We do not provide the required HF_API_KEY environment variable.
|
||||
test.runNvim = false;
|
||||
|
||||
plugins = {
|
||||
cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "cmp_ai"; } ];
|
||||
};
|
||||
cmp-ai.settings = {
|
||||
max_lines = 1000;
|
||||
provider = "HF";
|
||||
notify = true;
|
||||
notify_callback = ''
|
||||
function(msg)
|
||||
vim.notify(msg)
|
||||
end
|
||||
'';
|
||||
run_on_every_keystroke = true;
|
||||
ignored_file_types = {
|
||||
lua = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
16
tests/test-sources/plugins/cmp/cmp-async-path.nix
Normal file
16
tests/test-sources/plugins/cmp/cmp-async-path.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
example = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
settings.sources = [
|
||||
{
|
||||
name = "async_path";
|
||||
option = {
|
||||
trailing_slash = false;
|
||||
label_trailing_slash = true;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
285
tests/test-sources/plugins/cmp/cmp-git.nix
Normal file
285
tests/test-sources/plugins/cmp/cmp-git.nix
Normal file
|
@ -0,0 +1,285 @@
|
|||
{
|
||||
defaults = {
|
||||
plugins = {
|
||||
cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "git"; } ];
|
||||
};
|
||||
|
||||
cmp-git.settings = {
|
||||
filetypes = [
|
||||
"gitcommit"
|
||||
"octo"
|
||||
];
|
||||
remotes = [
|
||||
"upstream"
|
||||
"origin"
|
||||
];
|
||||
enableRemoteUrlRewrites = false;
|
||||
git = {
|
||||
commits = {
|
||||
limit = 100;
|
||||
sort_by = "require('cmp_git.sort').git.commits";
|
||||
format = "require('cmp_git.format').git.commits";
|
||||
};
|
||||
};
|
||||
github = {
|
||||
hosts = [ ];
|
||||
issues = {
|
||||
fields = [
|
||||
"title"
|
||||
"number"
|
||||
"body"
|
||||
"updatedAt"
|
||||
"state"
|
||||
];
|
||||
filter = "all";
|
||||
limit = 100;
|
||||
state = "open";
|
||||
sort_by = "require('cmp_git.sort').github.issues";
|
||||
format = "require('cmp_git.format').github.issues";
|
||||
};
|
||||
mentions = {
|
||||
limit = 100;
|
||||
sort_by = "require('cmp_git.sort').github.mentions";
|
||||
format = "require('cmp_git.format').github.mentions";
|
||||
};
|
||||
pull_requests = {
|
||||
fields = [
|
||||
"title"
|
||||
"number"
|
||||
"body"
|
||||
"updatedAt"
|
||||
"state"
|
||||
];
|
||||
limit = 100;
|
||||
state = "open";
|
||||
sort_by = "require('cmp_git.sort').github.pull_requests";
|
||||
format = "require('cmp_git.format').github.pull_requests";
|
||||
};
|
||||
};
|
||||
gitlab = {
|
||||
hosts = [ ];
|
||||
issues = {
|
||||
limit = 100;
|
||||
state = "opened";
|
||||
sort_by = "require('cmp_git.sort').gitlab.pull_requests";
|
||||
format = "require('cmp_git.format').gitlab.pull_requests";
|
||||
};
|
||||
mentions = {
|
||||
limit = 100;
|
||||
sort_by = "require('cmp_git.sort').gitlab.mentions";
|
||||
format = "require('cmp_git.format').gitlab.mentions";
|
||||
};
|
||||
merge_requests = {
|
||||
limit = 100;
|
||||
state = "opened";
|
||||
sort_by = "require('cmp_git.sort').gitlab.merge_requests";
|
||||
format = "require('cmp_git.format').gitlab.merge_requests";
|
||||
};
|
||||
};
|
||||
trigger_actions = [
|
||||
{
|
||||
debug_name = "git_commits";
|
||||
trigger_character = ":";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.git:get_commits(callback, params, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_issues";
|
||||
trigger_character = "#";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_issues(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_mentions";
|
||||
trigger_character = "@";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_mentions(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_mrs";
|
||||
trigger_character = "!";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_merge_requests(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "github_issues_and_pr";
|
||||
trigger_character = "#";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.github:get_issues_and_prs(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "github_mentions";
|
||||
trigger_character = "@";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.github:get_mentions(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
example = {
|
||||
plugins = {
|
||||
cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "git"; } ];
|
||||
};
|
||||
|
||||
cmp-git.settings = {
|
||||
remotes = [
|
||||
"upstream"
|
||||
"origin"
|
||||
"foo"
|
||||
];
|
||||
github = {
|
||||
issues = {
|
||||
filter = "all";
|
||||
limit = 250;
|
||||
state = "all";
|
||||
format = ''
|
||||
function(_, issue)
|
||||
local icon = ({
|
||||
open = '',
|
||||
closed = '',
|
||||
})[string.lower(issue.state)]
|
||||
return string.format('%s #%d: %s', icon, issue.number, issue.title)
|
||||
end
|
||||
'';
|
||||
sort_by = ''
|
||||
function(issue)
|
||||
local kind_rank = issue.pull_request and 1 or 0
|
||||
local state_rank = issue.state == 'open' and 0 or 1
|
||||
local age = os.difftime(os.time(), require('cmp_git.utils').parse_github_date(issue.updatedAt))
|
||||
return string.format('%d%d%010d', kind_rank, state_rank, age)
|
||||
end
|
||||
'';
|
||||
filter_fn.__raw = ''
|
||||
function(trigger_char, issue)
|
||||
return string.format('%s %s %s', trigger_char, issue.number, issue.title)
|
||||
end
|
||||
'';
|
||||
};
|
||||
mentions = {
|
||||
limit = 250;
|
||||
sort_by = null;
|
||||
filter_fn.__raw = ''
|
||||
function(trigger_char, mention)
|
||||
return string.format('%s %s %s', trigger_char, mention.username)
|
||||
end
|
||||
'';
|
||||
};
|
||||
pull_requests = {
|
||||
limit = 250;
|
||||
state = "all";
|
||||
format = ''
|
||||
function(_, pr)
|
||||
local icon = ({
|
||||
open = '',
|
||||
closed = '',
|
||||
})[string.lower(pr.state)]
|
||||
return string.format('%s #%d: %s', icon, pr.number, pr.title)
|
||||
end
|
||||
'';
|
||||
sort_by = ''
|
||||
function(pr)
|
||||
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))
|
||||
return string.format('%d%010d', state_rank, age)
|
||||
end
|
||||
'';
|
||||
filter_fn.__raw = ''
|
||||
function(trigger_char, pr)
|
||||
return string.format('%s %s %s', trigger_char, pr.number, pr.title)
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
trigger_actions = [
|
||||
{
|
||||
debug_name = "git_commits";
|
||||
trigger_character = ":";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.git:get_commits(callback, params, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "github_issues";
|
||||
trigger_character = "#";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.github:get_issues(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "github_pulls";
|
||||
trigger_character = "!";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.github:get_pull_requests(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "github_mentions";
|
||||
trigger_character = "@";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.github:get_mentions(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_issues";
|
||||
trigger_character = "#";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_issues(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_mentions";
|
||||
trigger_character = "@";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_mentions(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
{
|
||||
debug_name = "gitlab_mrs";
|
||||
trigger_character = "!";
|
||||
action = ''
|
||||
function(sources, trigger_char, callback, params, git_info)
|
||||
return sources.gitlab:get_merge_requests(callback, git_info, trigger_char)
|
||||
end
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
23
tests/test-sources/plugins/cmp/cmp-tabby.nix
Normal file
23
tests/test-sources/plugins/cmp/cmp-tabby.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
empty = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "cmp_tabby"; } ];
|
||||
};
|
||||
};
|
||||
|
||||
defaults = {
|
||||
plugins = {
|
||||
cmp = {
|
||||
enable = true;
|
||||
settings.sources = [ { name = "cmp_tabby"; } ];
|
||||
};
|
||||
cmp-tabby.settings = {
|
||||
host = "http://localhost:5000";
|
||||
max_lines = 100;
|
||||
run_on_every_keystroke = true;
|
||||
stop = [ "\n" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
284
tests/test-sources/plugins/cmp/default.nix
Normal file
284
tests/test-sources/plugins/cmp/default.nix
Normal file
|
@ -0,0 +1,284 @@
|
|||
{
|
||||
empty = {
|
||||
plugins.cmp.enable = true;
|
||||
};
|
||||
|
||||
snippet-engine = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
settings.snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end";
|
||||
};
|
||||
};
|
||||
|
||||
# Issue #536
|
||||
mappings = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
settings.mapping = {
|
||||
"<CR>" = "cmp.mapping.confirm({ select = false })";
|
||||
"<Tab>" = ''
|
||||
cmp.mapping(
|
||||
function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expandable() then
|
||||
luasnip.expand()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif check_backspace() then
|
||||
fallback()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
{ "i", "s" }
|
||||
)
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
defaults = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
performance = {
|
||||
debounce = 60;
|
||||
throttle = 30;
|
||||
fetchingTimeout = 500;
|
||||
asyncBudget = 1;
|
||||
maxViewEntries = 200;
|
||||
};
|
||||
preselect = "Item";
|
||||
snippet = {
|
||||
expand = ''
|
||||
function(_)
|
||||
error('snippet engine is not configured.')
|
||||
end
|
||||
'';
|
||||
};
|
||||
completion = {
|
||||
keywordLength = 1;
|
||||
keywordPattern = ''[[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]]'';
|
||||
autocomplete = [ "TextChanged" ];
|
||||
completeopt = "menu,menuone,noselect";
|
||||
};
|
||||
confirmation = {
|
||||
getCommitCharacters = ''
|
||||
function(commit_characters)
|
||||
return commit_characters
|
||||
end
|
||||
'';
|
||||
};
|
||||
formatting = {
|
||||
expandableIndicator = true;
|
||||
fields = [
|
||||
"abbr"
|
||||
"kind"
|
||||
"menu"
|
||||
];
|
||||
format = ''
|
||||
function(_, vim_item)
|
||||
return vim_item
|
||||
end
|
||||
'';
|
||||
};
|
||||
matching = {
|
||||
disallowFuzzyMatching = false;
|
||||
disallowFullfuzzyMatching = false;
|
||||
disallowPartialFuzzyMatching = true;
|
||||
disallowPartialMatching = false;
|
||||
disallowPrefixUnmatching = false;
|
||||
};
|
||||
sorting = {
|
||||
priorityWeight = 2;
|
||||
comparators = [
|
||||
"offset"
|
||||
"exact"
|
||||
"score"
|
||||
"recently_used"
|
||||
"locality"
|
||||
"kind"
|
||||
"length"
|
||||
"order"
|
||||
];
|
||||
};
|
||||
sources = [ ];
|
||||
experimental = {
|
||||
ghost_text = false;
|
||||
};
|
||||
view = {
|
||||
entries = {
|
||||
name = "custom";
|
||||
selection_order = "top_down";
|
||||
};
|
||||
docs = {
|
||||
autoOpen = true;
|
||||
};
|
||||
};
|
||||
window = {
|
||||
completion = {
|
||||
border = [
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
];
|
||||
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
|
||||
scrolloff = 0;
|
||||
colOffset = 0;
|
||||
sidePadding = 1;
|
||||
scrollbar = true;
|
||||
};
|
||||
documentation = {
|
||||
maxHeight = "math.floor(40 * (40 / vim.o.lines))";
|
||||
maxWidth = "math.floor((40 * 2) * (vim.o.columns / (40 * 2 * 16 / 9)))";
|
||||
border.__raw = "cmp.config.window.bordered()";
|
||||
winhighlight = "FloatBorder:NormalFloat";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
list-of-sources = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
settings.sources = [
|
||||
{ name = "path"; }
|
||||
{ name = "nvim_lsp"; }
|
||||
{ name = "luasnip"; }
|
||||
{
|
||||
name = "buffer";
|
||||
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
|
||||
}
|
||||
{ name = "neorg"; }
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
list-of-lists-of-sources = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
# Here we are setting sources with raw lua. This cannot be parsed by Nixvim.
|
||||
autoEnableSources = false;
|
||||
|
||||
settings.sources.__raw = ''
|
||||
cmp.config.sources({
|
||||
{
|
||||
{name = "path"},
|
||||
{name = "nvim_lsp"}
|
||||
},
|
||||
{
|
||||
{
|
||||
name = "buffer",
|
||||
option = {
|
||||
get_bufnrs = vim.api.nvim_list_bufs
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
example = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end";
|
||||
window = {
|
||||
completion.__raw = "cmp.config.window.bordered";
|
||||
documentation.__raw = "cmp.config.window.bordered";
|
||||
};
|
||||
|
||||
mapping = {
|
||||
"<C-b>" = "cmp.mapping.scroll_docs(-4)";
|
||||
"<C-f>" = "cmp.mapping.scroll_docs(4)";
|
||||
"<C-Space>" = "cmp.mapping.complete()";
|
||||
"<C-e>" = "cmp.mapping.abort()";
|
||||
"<CR>" = "cmp.mapping.confirm({ select = true })";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
readme-example = {
|
||||
plugins.cmp = {
|
||||
enable = true;
|
||||
|
||||
# Here we are setting sources with raw lua. This cannot be parsed by Nixvim.
|
||||
autoEnableSources = false;
|
||||
|
||||
settings = {
|
||||
mapping.__raw = ''
|
||||
cmp.mapping.preset.insert({
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
})
|
||||
'';
|
||||
sources.__raw = ''
|
||||
cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'vsnip' },
|
||||
-- { name = 'luasnip' },
|
||||
-- { name = 'ultisnips' },
|
||||
-- { name = 'snippy' },
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
'';
|
||||
};
|
||||
|
||||
filetype.gitcommit.sources.__raw = ''
|
||||
cmp.config.sources({
|
||||
{ name = 'git' },
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
'';
|
||||
|
||||
cmdline = {
|
||||
"/" = {
|
||||
mapping.__raw = "cmp.mapping.preset.cmdline()";
|
||||
# Need to use a raw lua string as we only accept **flat** lists (not nested).
|
||||
sources.__raw = ''
|
||||
{
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
'';
|
||||
};
|
||||
"?" = {
|
||||
mapping.__raw = "cmp.mapping.preset.cmdline()";
|
||||
# Need to use a raw lua string as we only accept **flat** lists (not nested).
|
||||
sources.__raw = ''
|
||||
{
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
'';
|
||||
};
|
||||
":" = {
|
||||
mapping.__raw = "cmp.mapping.preset.cmdline()";
|
||||
sources.__raw = ''
|
||||
cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
})
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue