mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-13 10:44:34 +02:00
plugins/nvim-cmp: allow users to provide a 'listOf listOf sources'
This commit is contained in:
parent
b393989ba5
commit
26626aa1b1
2 changed files with 71 additions and 12 deletions
|
@ -278,7 +278,7 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
sources = let
|
sources = let
|
||||||
source_config = types.submodule (_: {
|
source_config = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
@ -351,13 +351,25 @@ in {
|
||||||
Using the `ctx` parameter, you can further customize the behaviour of the source.
|
Using the `ctx` parameter, you can further customize the behaviour of the source.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
in
|
in
|
||||||
mkOption {
|
mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
type = with types; nullOr (listOf source_config);
|
type = with types;
|
||||||
|
nullOr
|
||||||
|
(
|
||||||
|
listOf
|
||||||
|
(
|
||||||
|
either
|
||||||
|
source_config
|
||||||
|
(listOf source_config)
|
||||||
|
)
|
||||||
|
);
|
||||||
description = ''
|
description = ''
|
||||||
The sources to use.
|
The sources to use.
|
||||||
|
Can either be a list of sourceConfigs which will be made directly to a Lua object.
|
||||||
|
Or it can be a list of lists, which will use the cmp built-in helper function
|
||||||
|
`cmp.config.sources`.
|
||||||
|
|
||||||
Default: `[]`
|
Default: `[]`
|
||||||
'';
|
'';
|
||||||
|
@ -588,9 +600,8 @@ in {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
sources = helpers.ifNonNull' cfg.sources (
|
sources = let
|
||||||
map
|
convertSourceAttrs = source:
|
||||||
(source:
|
|
||||||
with source; {
|
with source; {
|
||||||
inherit
|
inherit
|
||||||
name
|
name
|
||||||
|
@ -603,9 +614,21 @@ in {
|
||||||
inherit priority;
|
inherit priority;
|
||||||
group_index = groupIndex;
|
group_index = groupIndex;
|
||||||
entry_filter = entryFilter;
|
entry_filter = entryFilter;
|
||||||
})
|
};
|
||||||
cfg.sources
|
in
|
||||||
);
|
if sources == null || sources == []
|
||||||
|
then null
|
||||||
|
# List of lists of sources -> we use the `cmp.config.sources` helper
|
||||||
|
else if isList (head sources)
|
||||||
|
then let
|
||||||
|
sourcesListofLists =
|
||||||
|
map
|
||||||
|
(map convertSourceAttrs)
|
||||||
|
sources;
|
||||||
|
in
|
||||||
|
helpers.mkRaw "cmp.config.sources(${helpers.toLuaObject sourcesListofLists})"
|
||||||
|
# List of sources
|
||||||
|
else map convertSourceAttrs sources;
|
||||||
|
|
||||||
view = with view; {
|
view = with view; {
|
||||||
inherit entries;
|
inherit entries;
|
||||||
|
@ -656,10 +679,10 @@ in {
|
||||||
# If autoEnableSources is set to true, figure out which are provided by the user
|
# If autoEnableSources is set to true, figure out which are provided by the user
|
||||||
# and enable the corresponding plugins.
|
# and enable the corresponding plugins.
|
||||||
plugins = let
|
plugins = let
|
||||||
sourcesList =
|
sourcesFlattenedList =
|
||||||
if cfg.sources == null
|
if cfg.sources == null
|
||||||
then []
|
then []
|
||||||
else cfg.sources;
|
else flatten cfg.sources;
|
||||||
|
|
||||||
# Take only the names from the sources provided by the user
|
# Take only the names from the sources provided by the user
|
||||||
foundSources =
|
foundSources =
|
||||||
|
@ -667,7 +690,7 @@ in {
|
||||||
(
|
(
|
||||||
map
|
map
|
||||||
(source: source.name)
|
(source: source.name)
|
||||||
sourcesList
|
sourcesFlattenedList
|
||||||
);
|
);
|
||||||
|
|
||||||
# A list of known source names
|
# A list of known source names
|
||||||
|
|
|
@ -132,4 +132,40 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
list-of-sources = {
|
||||||
|
plugins.nvim-cmp = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
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.nvim-cmp = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
sources = [
|
||||||
|
[
|
||||||
|
{name = "path";}
|
||||||
|
{name = "nvim_lsp";}
|
||||||
|
]
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name = "buffer";
|
||||||
|
option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue