mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-28 11:30:06 +02:00
plugins/cmp: remove with lib;
This commit is contained in:
parent
d71cfaaae8
commit
62b87e5b56
13 changed files with 92 additions and 92 deletions
|
@ -1,38 +1,36 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.plugins.cmp;
|
||||
|
||||
extractSources = { sources, ... }: if isList sources then sources else [ ];
|
||||
extractSources = { sources, ... }: if lib.isList sources then sources else [ ];
|
||||
|
||||
# Collect the names of the sources provided by the user
|
||||
# ["foo" "bar"]
|
||||
enabledSources =
|
||||
pipe
|
||||
lib.pipe
|
||||
[
|
||||
# cfg.setup.sources
|
||||
(extractSources cfg.settings)
|
||||
# cfg.filetype.<name>.sources
|
||||
(mapAttrsToList (_: extractSources) cfg.filetype)
|
||||
(lib.mapAttrsToList (_: extractSources) cfg.filetype)
|
||||
# cfg.cmdline.<name>.sources
|
||||
(mapAttrsToList (_: extractSources) cfg.cmdline)
|
||||
(lib.mapAttrsToList (_: extractSources) cfg.cmdline)
|
||||
]
|
||||
[
|
||||
flatten
|
||||
(map (getAttr "name"))
|
||||
unique
|
||||
lib.flatten
|
||||
(map (lib.getAttr "name"))
|
||||
lib.unique
|
||||
];
|
||||
in
|
||||
{
|
||||
options = {
|
||||
# Note: this option must be outside of `plugins` to avoid infinite recursion
|
||||
cmpSourcePlugins = mkOption {
|
||||
type = with types; attrsOf str;
|
||||
cmpSourcePlugins = lib.mkOption {
|
||||
type = with lib.types; attrsOf str;
|
||||
default = { };
|
||||
description = ''
|
||||
Internal option used to associate nvim-cmp source names with nixvim plugin module names.
|
||||
|
@ -47,8 +45,8 @@ in
|
|||
visible = false;
|
||||
};
|
||||
|
||||
plugins.cmp.autoEnableSources = mkOption {
|
||||
type = types.bool;
|
||||
plugins.cmp.autoEnableSources = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
|
@ -57,11 +55,12 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf (cfg.enable && cfg.autoEnableSources) (mkMerge [
|
||||
config = lib.mkIf (cfg.enable && cfg.autoEnableSources) (
|
||||
lib.mkMerge [
|
||||
{
|
||||
warnings =
|
||||
# TODO: expand this warning to ft & cmd sources lists and `showDefs` the offending definitions
|
||||
optional (lib.types.isRawType cfg.settings.sources) ''
|
||||
lib.optional (lib.types.isRawType cfg.settings.sources) ''
|
||||
Nixvim (plugins.cmp): You have enabled `autoEnableSources` that tells Nixvim to automatically
|
||||
enable the source plugins with respect to the list of sources provided in `settings.sources`.
|
||||
However, the latter is proveded as a raw lua string which is not parseable by Nixvim.
|
||||
|
@ -71,7 +70,7 @@ in
|
|||
- Dismiss this warning by explicitly setting `autoEnableSources` to `false`;
|
||||
''
|
||||
# TODO: Added 2024-09-22; remove after 24.11
|
||||
++ optional (elem "otter" enabledSources) ''
|
||||
++ lib.optional (lib.elem "otter" enabledSources) ''
|
||||
Nixvim (plugins.cmp): "otter" is listed in `settings.sources`, however it is no longer a cmp source.
|
||||
Instead, you should enable `plugins.otter` and use the "cmp-nvim-lsp" completion source.
|
||||
'';
|
||||
|
@ -81,15 +80,16 @@ in
|
|||
# cmp-foo.enable = true;
|
||||
# cmp-bar.enable = true;
|
||||
# }
|
||||
plugins = mapAttrs' (source: name: {
|
||||
plugins = lib.mapAttrs' (source: name: {
|
||||
inherit name;
|
||||
value.enable = mkIf (elem source enabledSources) true;
|
||||
value.enable = lib.mkIf (lib.elem source enabledSources) true;
|
||||
}) config.cmpSourcePlugins;
|
||||
}
|
||||
{
|
||||
plugins.lsp.capabilities = mkIf (elem "nvim_lsp" enabledSources) ''
|
||||
plugins.lsp.capabilities = lib.mkIf (lib.elem "nvim_lsp" enabledSources) ''
|
||||
capabilities = vim.tbl_deep_extend("force", capabilities, require('cmp_nvim_lsp').default_capabilities())
|
||||
'';
|
||||
}
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
let
|
||||
cmpOptions = import ./options { inherit lib helpers; };
|
||||
in
|
||||
with lib;
|
||||
helpers.neovim-plugin.mkNeovimPlugin {
|
||||
name = "cmp";
|
||||
originalName = "nvim-cmp";
|
||||
package = "nvim-cmp";
|
||||
|
||||
maintainers = [ maintainers.GaetanLepage ];
|
||||
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||
|
||||
description = ''
|
||||
### Completion Source Installation
|
||||
|
@ -76,13 +75,13 @@ helpers.neovim-plugin.mkNeovimPlugin {
|
|||
cmp.setup(${helpers.toLuaObject cfg.settings})
|
||||
|
||||
''
|
||||
+ (concatStringsSep "\n" (
|
||||
mapAttrsToList (
|
||||
+ (lib.concatStringsSep "\n" (
|
||||
lib.mapAttrsToList (
|
||||
filetype: settings: "cmp.setup.filetype('${filetype}', ${helpers.toLuaObject settings})\n"
|
||||
) cfg.filetype
|
||||
))
|
||||
+ (concatStringsSep "\n" (
|
||||
mapAttrsToList (
|
||||
+ (lib.concatStringsSep "\n" (
|
||||
lib.mapAttrsToList (
|
||||
cmdtype: settings: "cmp.setup.cmdline('${cmdtype}', ${helpers.toLuaObject settings})\n"
|
||||
) cfg.cmdline
|
||||
));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib) mkRenamedOptionModule mkRemovedOptionModule;
|
||||
|
||||
oldPluginBasePath = [
|
||||
"plugins"
|
||||
"nvim-cmp"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{ lib, helpers }:
|
||||
with lib;
|
||||
rec {
|
||||
settingsOptions = import ./settings-options.nix { inherit lib helpers; };
|
||||
|
||||
|
@ -28,13 +27,13 @@ rec {
|
|||
};
|
||||
|
||||
attrsOfOptions =
|
||||
with types;
|
||||
with lib.types;
|
||||
attrsOf (submodule {
|
||||
freeformType = attrsOf anything;
|
||||
options = settingsOptions;
|
||||
});
|
||||
|
||||
filetype = mkOption {
|
||||
filetype = lib.mkOption {
|
||||
type = attrsOfOptions;
|
||||
default = { };
|
||||
description = "Options provided to the `require('cmp').setup.filetype` function.";
|
||||
|
@ -45,7 +44,7 @@ rec {
|
|||
};
|
||||
};
|
||||
|
||||
cmdline = mkOption {
|
||||
cmdline = lib.mkOption {
|
||||
type = attrsOfOptions;
|
||||
default = { };
|
||||
description = "Options provided to the `require('cmp').setup.cmdline` function.";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{ lib, helpers }:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
performance = {
|
||||
debounce = helpers.defaultNullOpts.mkUnsignedInt 60 ''
|
||||
|
@ -261,7 +263,9 @@ with lib;
|
|||
in
|
||||
{
|
||||
completion = {
|
||||
border = helpers.defaultNullOpts.mkBorder (genList (_: "") 8) "nvim-cmp completion popup menu" "";
|
||||
border = helpers.defaultNullOpts.mkBorder (lib.genList (
|
||||
_: ""
|
||||
) 8) "nvim-cmp completion popup menu" "";
|
||||
|
||||
winhighlight = mkWinhighlightOption "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None";
|
||||
|
||||
|
@ -286,7 +290,7 @@ with lib;
|
|||
};
|
||||
|
||||
documentation = {
|
||||
border = helpers.defaultNullOpts.mkBorder (genList (
|
||||
border = helpers.defaultNullOpts.mkBorder (lib.genList (
|
||||
_: ""
|
||||
) 8) "nvim-cmp documentation popup menu" "";
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{ lib, helpers }:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib) types;
|
||||
|
||||
sourceType = types.submodule {
|
||||
freeformType = with types; attrsOf anything;
|
||||
options = {
|
||||
name = mkOption {
|
||||
name = lib.mkOption {
|
||||
type = types.str;
|
||||
description = "The name of the source.";
|
||||
example = "buffer";
|
||||
|
@ -79,7 +80,7 @@ let
|
|||
};
|
||||
};
|
||||
in
|
||||
mkOption {
|
||||
lib.mkOption {
|
||||
default = [ ];
|
||||
type = with lib.types; maybeRaw (listOf sourceType);
|
||||
description = ''
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.plugins.cmp-ai;
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ maintainers.GaetanLepage ];
|
||||
meta.maintainers = [ lib.maintainers.GaetanLepage ];
|
||||
|
||||
options.plugins.cmp-ai = {
|
||||
settings = helpers.mkSettingsOption {
|
||||
|
@ -31,7 +30,7 @@ in
|
|||
available options.
|
||||
'';
|
||||
|
||||
provider_options = helpers.defaultNullOpts.mkAttrsOf types.anything { } ''
|
||||
provider_options = helpers.defaultNullOpts.mkAttrsOf lib.types.anything { } ''
|
||||
Options to forward to the provider.
|
||||
'';
|
||||
|
||||
|
@ -60,7 +59,7 @@ in
|
|||
};
|
||||
|
||||
ignored_file_types = helpers.defaultNullOpts.mkAttrsOf' {
|
||||
type = types.bool;
|
||||
type = lib.types.bool;
|
||||
description = "Which filetypes to ignore.";
|
||||
pluginDefault = { };
|
||||
example = {
|
||||
|
@ -87,7 +86,7 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('cmp_ai.config'):setup(${helpers.toLuaObject cfg.settings})
|
||||
'';
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
helpers,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.plugins.cmp-fish;
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ maintainers.GaetanLepage ];
|
||||
meta.maintainers = [ lib.maintainers.GaetanLepage ];
|
||||
|
||||
options.plugins.cmp-fish = {
|
||||
fishPackage = lib.mkPackageOption pkgs "fish" {
|
||||
|
@ -18,5 +16,5 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable { extraPackages = [ cfg.fishPackage ]; };
|
||||
config = lib.mkIf cfg.enable { extraPackages = [ cfg.fishPackage ]; };
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib) types;
|
||||
cfg = config.plugins.cmp-git;
|
||||
|
||||
mkAction =
|
||||
action: target:
|
||||
helpers.defaultNullOpts.mkLuaFn "require('cmp_git.${action}').git.${target}" ''
|
||||
Function used to ${action} the ${replaceStrings [ "_" ] [ " " ] target}.
|
||||
Function used to ${action} the ${lib.replaceStrings [ "_" ] [ " " ] target}.
|
||||
'';
|
||||
in
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ in
|
|||
options = {
|
||||
debug_name = helpers.mkNullOrStr "Debug name.";
|
||||
|
||||
trigger_character = mkOption {
|
||||
trigger_character = lib.mkOption {
|
||||
type = types.str;
|
||||
example = ":";
|
||||
description = ''
|
||||
|
@ -160,7 +160,7 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
action = mkOption {
|
||||
action = lib.mkOption {
|
||||
type = lib.types.strLuaFn;
|
||||
description = ''
|
||||
The parameters to the action function are the different sources (currently `git`,
|
||||
|
@ -289,7 +289,7 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('cmp_git').setup(${helpers.toLuaObject cfg.settings})
|
||||
'';
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
inherit (lib) mkRenamedOptionModule types;
|
||||
cfg = config.plugins.cmp-tabby;
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ maintainers.GaetanLepage ];
|
||||
meta.maintainers = [ lib.maintainers.GaetanLepage ];
|
||||
|
||||
# TODO: introduced 24-06-18, remove after 24.11
|
||||
imports =
|
||||
|
@ -61,7 +61,7 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('cmp_tabby.config'):setup(${helpers.toLuaObject cfg.settings})
|
||||
'';
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.plugins.cmp-tabnine;
|
||||
in
|
||||
{
|
||||
options.plugins.cmp-tabnine = helpers.neovim-plugin.extraOptionsOptions;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('cmp_tabnine.config'):setup(${helpers.toLuaObject cfg.extraOptions})
|
||||
'';
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
copilot-lua-cfg = config.plugins.copilot-lua;
|
||||
cfg = config.plugins.copilot-cmp;
|
||||
|
@ -12,7 +11,7 @@ in
|
|||
{
|
||||
options.plugins.copilot-cmp = helpers.neovim-plugin.extraOptionsOptions // {
|
||||
event =
|
||||
helpers.defaultNullOpts.mkListOf types.str
|
||||
helpers.defaultNullOpts.mkListOf lib.types.str
|
||||
[
|
||||
"InsertEnter"
|
||||
"LspAttach"
|
||||
|
@ -35,13 +34,15 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
warnings =
|
||||
optional ((!isBool copilot-lua-cfg.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled) ''
|
||||
lib.optional
|
||||
((!lib.isBool copilot-lua-cfg.suggestion.enabled) || copilot-lua-cfg.suggestion.enabled)
|
||||
''
|
||||
It is recommended to disable copilot's `suggestion` module, as it can interfere with
|
||||
completions properly appearing in copilot-cmp.
|
||||
''
|
||||
++ optional ((!isBool copilot-lua-cfg.panel.enabled) || copilot-lua-cfg.panel.enabled) ''
|
||||
++ lib.optional ((!lib.isBool copilot-lua-cfg.panel.enabled) || copilot-lua-cfg.panel.enabled) ''
|
||||
It is recommended to disable copilot's `panel` module, as it can interfere with completions
|
||||
properly appearing in copilot-cmp.
|
||||
'';
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
config,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.plugins.crates-nvim;
|
||||
in
|
||||
{
|
||||
options.plugins.crates-nvim = helpers.neovim-plugin.extraOptionsOptions;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('crates').setup(${helpers.toLuaObject cfg.extraOptions})
|
||||
'';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue