nix-community.nixvim/plugins/cmp/sources/cmp-ai.nix

96 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2024-06-14 11:06:45 +02:00
{
lib,
config,
...
}:
let
2024-10-06 10:05:31 -05:00
inherit (lib.nixvim) defaultNullOpts;
2024-06-14 11:06:45 +02:00
cfg = config.plugins.cmp-ai;
in
{
2024-10-06 09:57:31 -05:00
meta.maintainers = [ lib.maintainers.GaetanLepage ];
2024-06-14 11:06:45 +02:00
options.plugins.cmp-ai = {
2024-10-06 10:05:31 -05:00
settings = lib.nixvim.mkSettingsOption {
2024-06-14 11:06:45 +02:00
description = "Options provided to the `require('cmp_ai.config'):setup` function.";
options = {
2024-10-06 10:05:31 -05:00
max_lines = defaultNullOpts.mkUnsignedInt 50 ''
2024-06-14 11:06:45 +02:00
How many lines of buffer context to use.
'';
2024-10-06 10:05:31 -05:00
run_on_every_keystroke = defaultNullOpts.mkBool true ''
2024-06-14 11:06:45 +02:00
Generate new completion items on every keystroke.
'';
2024-10-06 10:05:31 -05:00
provider = defaultNullOpts.mkStr "HF" ''
2024-06-14 11:06:45 +02:00
Which AI provider to use.
Check the [README](https://github.com/tzachar/cmp-ai/blob/main/README.md) to learn about
available options.
'';
2024-10-06 10:05:31 -05:00
provider_options = defaultNullOpts.mkAttrsOf lib.types.anything { } ''
2024-06-14 11:06:45 +02:00
Options to forward to the provider.
'';
2024-10-06 10:05:31 -05:00
notify = defaultNullOpts.mkBool true ''
2024-06-14 11:06:45 +02:00
As some completion sources can be quit slow, setting this to `true` will trigger a
notification when a completion starts and ends using `vim.notify`.
'';
2024-10-06 10:05:31 -05:00
notify_callback = defaultNullOpts.mkLuaFn' {
2024-06-14 11:06:45 +02:00
description = ''
The default notify function uses `vim.notify`, but an override can be configured.
'';
pluginDefault = ''
function(msg)
vim.notify(msg)
end
'';
example = ''
function(msg)
require('notify').notify(msg, vim.log.levels.INFO, {
title = 'OpenAI',
render = 'compact',
})
end
'';
};
2024-10-06 10:05:31 -05:00
ignored_file_types = defaultNullOpts.mkAttrsOf' {
2024-10-06 09:57:31 -05:00
type = lib.types.bool;
2024-06-14 11:06:45 +02:00
description = "Which filetypes to ignore.";
pluginDefault = { };
example = {
lua = true;
html = true;
};
};
};
example = {
max_lines = 1000;
provider = "HF";
notify = true;
notify_callback = ''
function(msg)
vim.notify(msg)
end
'';
run_on_every_keystroke = true;
ignored_file_types = {
lua = true;
};
};
};
};
2024-10-06 09:57:31 -05:00
config = lib.mkIf cfg.enable {
2024-06-14 11:06:45 +02:00
extraConfigLua = ''
2024-10-06 10:05:31 -05:00
require('cmp_ai.config'):setup(${lib.nixvim.toLuaObject cfg.settings})
2024-06-14 11:06:45 +02:00
'';
};
}