2024-08-08 09:58:48 +08:00
|
|
|
{...}: {
|
2024-08-04 21:19:37 +08:00
|
|
|
# Autocompletion plugin
|
|
|
|
plugins.cmp = {
|
|
|
|
enable = true;
|
|
|
|
# Options provided to the require('cmp').setup function.
|
|
|
|
settings = {
|
|
|
|
# The sources to use
|
|
|
|
sources = [
|
2024-08-08 09:58:48 +08:00
|
|
|
{name = "nvim_lsp";} # LSP source for cmp
|
|
|
|
{name = "luasnip";} # Snippets source for cmp
|
2024-08-12 21:01:30 +08:00
|
|
|
{name = "path";} # Filesystem paths
|
2024-08-04 21:19:37 +08:00
|
|
|
];
|
|
|
|
# The snippet expansion function.
|
|
|
|
snippet.expand = ''
|
|
|
|
function(args)
|
|
|
|
require('luasnip').lsp_expand(args.body)
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
# cmp mappings declaration
|
|
|
|
mapping = {
|
|
|
|
# Select next/previous item.
|
2024-08-12 21:01:30 +08:00
|
|
|
"<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
|
|
|
|
"<S-Tab>" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})";
|
2024-08-04 21:19:37 +08:00
|
|
|
# Scroll through documentation.
|
|
|
|
"<C-s>" = "cmp.mapping.scroll_docs(-4)";
|
|
|
|
"<C-t>" = "cmp.mapping.scroll_docs(4)";
|
|
|
|
# Confirm selection.
|
2024-08-12 21:01:30 +08:00
|
|
|
"<CR>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
|
2024-08-04 21:19:37 +08:00
|
|
|
# Exit completion.
|
2024-08-12 21:01:30 +08:00
|
|
|
"<C-e>" = "cmp.mapping.abort()";
|
2024-08-04 21:19:37 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
# Scans the sources array and enable the corresponding plugins if they are known to nixvim.
|
|
|
|
autoEnableSources = true;
|
|
|
|
};
|
|
|
|
}
|