plugins/cmp: refactor source->plugin association

Introduce the internal option `cmpSourcePlugins` where plugins can
register their nvim-cmp source name association.
This commit is contained in:
Matt Sturgeon 2024-06-29 08:26:56 +01:00
parent bd422db9ba
commit 3a8d4fee35
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
6 changed files with 137 additions and 100 deletions

View file

@ -1,30 +1,39 @@
{ pkgs, cmp-sources, ... }:
{ pkgs, ... }:
{
all-sources = {
plugins = {
copilot-lua = {
enable = true;
module =
{ config, ... }:
{
plugins = {
copilot-lua = {
enable = true;
panel.enabled = false;
suggestion.enabled = false;
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"
] ++ 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;
}))
];
};
};
};
cmp = {
enable = true;
settings.sources =
with pkgs.lib;
let
disabledSources = [
# We do not provide the required HF_API_KEY environment variable.
"cmp_ai"
] ++ optional (pkgs.stdenv.hostPlatform.system == "aarch64-linux") "cmp_tabnine";
filterFunc = sourceName: !(elem sourceName disabledSources);
sourceNames = filter filterFunc (attrNames cmp-sources);
in
map (sourceName: { name = sourceName; }) sourceNames;
};
};
};
}