mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-26 10:48:35 +02:00
plugins/nvim-cmp: add enum type for option snippet.expand (#244)
This commit is contained in:
parent
bfbe737aa3
commit
c34c941c8f
2 changed files with 49 additions and 18 deletions
|
@ -8,6 +8,13 @@ with lib; let
|
||||||
cfg = config.plugins.nvim-cmp;
|
cfg = config.plugins.nvim-cmp;
|
||||||
helpers = import ../../helpers.nix {inherit lib;};
|
helpers = import ../../helpers.nix {inherit lib;};
|
||||||
cmpLib = import ./cmp-helpers.nix args;
|
cmpLib = import ./cmp-helpers.nix args;
|
||||||
|
|
||||||
|
snippetEngines = {
|
||||||
|
"vsnip" = ''vim.fn["vsnip#anonymous"](args.body)'';
|
||||||
|
"luasnip" = ''require('luasnip').lsp_expand(args.body)'';
|
||||||
|
"snippy" = ''require('snippy').expand_snippet(args.body)'';
|
||||||
|
"ultisnips" = ''vim.fn["UltiSnips#Anon"](args.body)'';
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.plugins.nvim-cmp = {
|
options.plugins.nvim-cmp = {
|
||||||
enable = mkEnableOption "nvim-cmp";
|
enable = mkEnableOption "nvim-cmp";
|
||||||
|
@ -94,24 +101,34 @@ in {
|
||||||
|
|
||||||
snippet = helpers.mkCompositeOption "Snippet options" {
|
snippet = helpers.mkCompositeOption "Snippet options" {
|
||||||
expand =
|
expand =
|
||||||
helpers.defaultNullOpts.mkStr
|
helpers.mkNullOrOption
|
||||||
''
|
(
|
||||||
function(_)
|
types.either
|
||||||
error('snippet engine is not configured.')
|
helpers.rawType
|
||||||
end
|
(types.enum (attrNames snippetEngines))
|
||||||
''
|
)
|
||||||
''
|
''
|
||||||
The snippet expansion function. That's how nvim-cmp interacts with a
|
The snippet expansion function. That's how nvim-cmp interacts with a
|
||||||
particular snippet engine.
|
particular snippet engine.
|
||||||
|
|
||||||
Example:
|
You may directly provide one of those four supported engines:
|
||||||
|
- vsnip
|
||||||
|
- luasnip
|
||||||
|
- snippy
|
||||||
|
- ultisnips
|
||||||
|
|
||||||
|
You can also provide a custom function:
|
||||||
```
|
```
|
||||||
function(args)
|
{
|
||||||
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
__raw = \'\'
|
||||||
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
function(args)
|
||||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
||||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||||
end
|
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
||||||
|
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
||||||
|
end
|
||||||
|
\'\';
|
||||||
|
};
|
||||||
```
|
```
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -486,10 +503,17 @@ in {
|
||||||
helpers.mkRaw wrapped;
|
helpers.mkRaw wrapped;
|
||||||
|
|
||||||
snippet = helpers.ifNonNull' cfg.snippet {
|
snippet = helpers.ifNonNull' cfg.snippet {
|
||||||
expand =
|
expand = let
|
||||||
helpers.ifNonNull'
|
expand = cfg.snippet.expand;
|
||||||
cfg.snippet.expand
|
in
|
||||||
(helpers.mkRaw cfg.snippet.expand);
|
if isString expand
|
||||||
|
then
|
||||||
|
helpers.mkRaw ''
|
||||||
|
function(args)
|
||||||
|
${snippetEngines.${expand}}
|
||||||
|
end
|
||||||
|
''
|
||||||
|
else expand;
|
||||||
};
|
};
|
||||||
|
|
||||||
completion = helpers.ifNonNull' cfg.completion {
|
completion = helpers.ifNonNull' cfg.completion {
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
plugins.nvim-cmp.enable = true;
|
plugins.nvim-cmp.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
snippetEngine = {
|
||||||
|
plugins.nvim-cmp = {
|
||||||
|
enable = true;
|
||||||
|
snippet.expand = "luasnip";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# All the upstream default options of nvim-cmp
|
# All the upstream default options of nvim-cmp
|
||||||
defaults = {
|
defaults = {
|
||||||
plugins.nvim-cmp = {
|
plugins.nvim-cmp = {
|
||||||
|
@ -18,7 +25,7 @@
|
||||||
preselect = "Item";
|
preselect = "Item";
|
||||||
|
|
||||||
snippet = {
|
snippet = {
|
||||||
expand = ''
|
expand.__raw = ''
|
||||||
function(_)
|
function(_)
|
||||||
error('snippet engine is not configured.')
|
error('snippet engine is not configured.')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue