mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-10 01:04:34 +02:00
plugins/nvim-cmp: refactoring (init filetype and cmdline options)
This commit is contained in:
parent
22b587f3dc
commit
a61c8fbc3d
26 changed files with 1166 additions and 948 deletions
44
plugins/completion/cmp/sources/cmp-tabby.nix
Normal file
44
plugins/completion/cmp/sources/cmp-tabby.nix
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.plugins.cmp-tabby;
|
||||
in {
|
||||
meta.maintainers = [maintainers.GaetanLepage];
|
||||
|
||||
options.plugins.cmp-tabby =
|
||||
helpers.neovim-plugin.extraOptionsOptions
|
||||
// {
|
||||
host = helpers.defaultNullOpts.mkStr "http://localhost:5000" ''
|
||||
The adress of the tabby host server.
|
||||
'';
|
||||
|
||||
maxLines = helpers.defaultNullOpts.mkUnsignedInt 100 ''
|
||||
The max number of lines to complete.
|
||||
'';
|
||||
|
||||
runOnEveryKeyStroke = helpers.defaultNullOpts.mkBool true ''
|
||||
Whether to run the completion on every keystroke.
|
||||
'';
|
||||
|
||||
stop = helpers.defaultNullOpts.mkListOf types.str ''["\n"]'' "";
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
extraConfigLua = let
|
||||
setupOptions = with cfg;
|
||||
{
|
||||
inherit host;
|
||||
max_lines = maxLines;
|
||||
run_on_every_keystroke = runOnEveryKeyStroke;
|
||||
inherit stop;
|
||||
}
|
||||
// cfg.extraOptions;
|
||||
in ''
|
||||
require('cmp_tabby.config'):setup(${helpers.toLuaObject setupOptions})
|
||||
'';
|
||||
};
|
||||
}
|
17
plugins/completion/cmp/sources/cmp-tabnine.nix
Normal file
17
plugins/completion/cmp/sources/cmp-tabnine.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.plugins.cmp-tabnine;
|
||||
in {
|
||||
options.plugins.cmp-tabnine = helpers.neovim-plugin.extraOptionsOptions;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('cmp_tabnine.config'):setup(${helpers.toLuaObject cfg.extraOptions})
|
||||
'';
|
||||
};
|
||||
}
|
89
plugins/completion/cmp/sources/codeium-nvim.nix
Normal file
89
plugins/completion/cmp/sources/codeium-nvim.nix
Normal file
|
@ -0,0 +1,89 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.plugins.codeium-nvim;
|
||||
in {
|
||||
meta.maintainers = [maintainers.GaetanLepage];
|
||||
|
||||
options.plugins.codeium-nvim =
|
||||
helpers.neovim-plugin.extraOptionsOptions
|
||||
// {
|
||||
package = helpers.mkPackageOption "codeium.nvim" pkgs.vimPlugins.codeium-nvim;
|
||||
|
||||
configPath =
|
||||
helpers.defaultNullOpts.mkStr
|
||||
''{__raw = "vim.fn.stdpath('cache') .. '/codeium/config.json'";}''
|
||||
"The path to the config file, used to store the API key.";
|
||||
|
||||
binPath =
|
||||
helpers.defaultNullOpts.mkStr
|
||||
''{__raw = "vim.fn.stdpath('cache') .. '/codeium/bin'";}''
|
||||
"The path to the directory where the Codeium server will be downloaded to.";
|
||||
|
||||
api = {
|
||||
host = helpers.defaultNullOpts.mkStr "server.codeium.com" ''
|
||||
The hostname of the API server to use.
|
||||
'';
|
||||
|
||||
port = helpers.defaultNullOpts.mkPositiveInt 443 ''
|
||||
The port of the API server to use.
|
||||
'';
|
||||
};
|
||||
|
||||
tools = {
|
||||
uname = helpers.mkNullOrOption types.str "The path to the `uname` binary.";
|
||||
|
||||
uuidgen = helpers.mkNullOrOption types.str "The path to the `uuidgen` binary.";
|
||||
|
||||
curl = helpers.mkNullOrOption types.str "The path to the `curl` binary.";
|
||||
|
||||
gzip = helpers.mkNullOrOption types.str "The path to the `gzip` binary.";
|
||||
|
||||
languageServer = helpers.mkNullOrOption types.str ''
|
||||
The path to the language server downloaded from the official source.
|
||||
'';
|
||||
};
|
||||
|
||||
wrapper = helpers.mkNullOrOption types.str ''
|
||||
The path to a wrapper script/binary that is used to execute any binaries not listed under
|
||||
tools.
|
||||
This is primarily useful for NixOS, where a FHS wrapper can be used for the downloaded
|
||||
codeium server.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
extraConfigLua = let
|
||||
setupOptions = with cfg;
|
||||
{
|
||||
config_path = configPath;
|
||||
bin_path = binPath;
|
||||
api = with api; {
|
||||
inherit host;
|
||||
port =
|
||||
if isInt port
|
||||
then toString port
|
||||
else port;
|
||||
};
|
||||
tools = with tools; {
|
||||
inherit
|
||||
uname
|
||||
uuidgen
|
||||
curl
|
||||
gzip
|
||||
;
|
||||
language_server = languageServer;
|
||||
};
|
||||
inherit wrapper;
|
||||
}
|
||||
// cfg.extraOptions;
|
||||
in ''
|
||||
require('codeium').setup(${helpers.toLuaObject setupOptions})
|
||||
'';
|
||||
};
|
||||
}
|
66
plugins/completion/cmp/sources/copilot-cmp.nix
Normal file
66
plugins/completion/cmp/sources/copilot-cmp.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
copilot-lua-cfg = config.plugins.copilot-lua;
|
||||
cfg = config.plugins.copilot-cmp;
|
||||
in {
|
||||
options.plugins.copilot-cmp =
|
||||
helpers.neovim-plugin.extraOptionsOptions
|
||||
// {
|
||||
event =
|
||||
helpers.defaultNullOpts.mkNullable
|
||||
(with types; listOf str)
|
||||
''["InsertEnter" "LspAttach"]''
|
||||
''
|
||||
Configures when the source is registered.
|
||||
Unless you have a unique problem for your particular configuration you probably don't want
|
||||
to touch this.
|
||||
'';
|
||||
|
||||
fixPairs = helpers.defaultNullOpts.mkBool true ''
|
||||
Suppose you have the following code: `print('h')`.
|
||||
Copilot might try to account for the `'` and `)` and complete it with this: `print('hello`.
|
||||
|
||||
This is not good behavior for consistency reasons and will just end up deleting the two ending
|
||||
characters.
|
||||
This option fixes that.
|
||||
Don't turn this off unless you are having problems with pairs and believe this might be
|
||||
causing them.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
warnings =
|
||||
optional
|
||||
((!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
|
||||
)
|
||||
''
|
||||
It is recommended to disable copilot's `panel` module, as it can interfere with completions
|
||||
properly appearing in copilot-cmp.
|
||||
'';
|
||||
|
||||
plugins.copilot-lua.enable = true;
|
||||
|
||||
extraConfigLua = let
|
||||
setupOptions = with cfg;
|
||||
{
|
||||
inherit event;
|
||||
fix_pairs = fixPairs;
|
||||
}
|
||||
// cfg.extraOptions;
|
||||
in ''
|
||||
require('copilot_cmp').setup(${helpers.toLuaObject setupOptions})
|
||||
'';
|
||||
};
|
||||
}
|
17
plugins/completion/cmp/sources/crates-nvim.nix
Normal file
17
plugins/completion/cmp/sources/crates-nvim.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
lib,
|
||||
helpers,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.plugins.crates-nvim;
|
||||
in {
|
||||
options.plugins.crates-nvim = helpers.neovim-plugin.extraOptionsOptions;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
extraConfigLua = ''
|
||||
require('crates').setup(${helpers.toLuaObject cfg.extraOptions})
|
||||
'';
|
||||
};
|
||||
}
|
29
plugins/completion/cmp/sources/default.nix
Normal file
29
plugins/completion/cmp/sources/default.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
helpers,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cmpLib = import ../cmp-helpers.nix {inherit lib config helpers pkgs;};
|
||||
cmpSourcesPluginNames = attrValues cmpLib.pluginAndSourceNames;
|
||||
pluginModules =
|
||||
map
|
||||
(
|
||||
name:
|
||||
cmpLib.mkCmpSourcePlugin {inherit name;}
|
||||
)
|
||||
cmpSourcesPluginNames;
|
||||
in {
|
||||
# For extra cmp plugins
|
||||
imports =
|
||||
[
|
||||
./codeium-nvim.nix
|
||||
./copilot-cmp.nix
|
||||
./cmp-tabby.nix
|
||||
./cmp-tabnine.nix
|
||||
./crates-nvim.nix
|
||||
]
|
||||
++ pluginModules;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue