mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
125 lines
3.1 KiB
Nix
125 lines
3.1 KiB
Nix
|
{
|
||
|
lib,
|
||
|
helpers,
|
||
|
config,
|
||
|
pkgs,
|
||
|
...
|
||
|
}:
|
||
|
with lib; let
|
||
|
cfg = config.plugins.wtf;
|
||
|
|
||
|
defaultKeymaps = {
|
||
|
ai = {
|
||
|
key = "gw";
|
||
|
mode = ["n" "x"];
|
||
|
action = "require('wtf').ai";
|
||
|
lua = true;
|
||
|
};
|
||
|
|
||
|
search = {
|
||
|
key = "gW";
|
||
|
mode = "n";
|
||
|
action = "require('wtf').search";
|
||
|
lua = true;
|
||
|
};
|
||
|
};
|
||
|
in {
|
||
|
options = {
|
||
|
plugins.wtf =
|
||
|
helpers.extraOptionsOptions
|
||
|
// {
|
||
|
enable = mkEnableOption "wtf.nvim";
|
||
|
|
||
|
package = helpers.mkPackageOption "wtf.nvim" pkgs.vimPlugins.wtf-nvim;
|
||
|
|
||
|
keymaps =
|
||
|
mapAttrs
|
||
|
(
|
||
|
action: defaults:
|
||
|
helpers.mkNullOrOption
|
||
|
(
|
||
|
with types;
|
||
|
either
|
||
|
str
|
||
|
(helpers.keymaps.mkMapOptionSubmodule defaults)
|
||
|
)
|
||
|
"Keymap for the ${action} action."
|
||
|
)
|
||
|
defaultKeymaps;
|
||
|
|
||
|
popupType = helpers.defaultNullOpts.mkEnum ["popup" "horizontal" "vertical"] "popup" ''
|
||
|
Default AI popup type.
|
||
|
'';
|
||
|
|
||
|
openaiApiKey = helpers.mkNullOrOption (with types; either str helpers.rawType) ''
|
||
|
An alternative way to set your API key.
|
||
|
'';
|
||
|
|
||
|
openaiModelId = helpers.defaultNullOpts.mkStr "gpt-3.5-turbo" "ChatGPT Model.";
|
||
|
|
||
|
context = helpers.defaultNullOpts.mkBool true "Send code as well as diagnostics.";
|
||
|
|
||
|
language = helpers.defaultNullOpts.mkStr "english" ''
|
||
|
Set your preferred language for the response.
|
||
|
'';
|
||
|
|
||
|
additionalInstructions = helpers.mkNullOrOption types.str "Any additional instructions.";
|
||
|
|
||
|
searchEngine =
|
||
|
helpers.defaultNullOpts.mkEnum
|
||
|
["google" "duck_duck_go" "stack_overflow" "github"]
|
||
|
"google"
|
||
|
"Default search engine.";
|
||
|
|
||
|
hooks = {
|
||
|
requestStarted = helpers.mkNullOrOption types.str "Callback for request start.";
|
||
|
|
||
|
requestFinished = helpers.mkNullOrOption types.str "Callback for request finished.";
|
||
|
};
|
||
|
|
||
|
winhighlight = helpers.defaultNullOpts.mkStr "Normal:Normal,FloatBorder:FloatBorder" ''
|
||
|
Add custom colours.
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config = let
|
||
|
setupOptions = with cfg;
|
||
|
{
|
||
|
popup_type = popupType;
|
||
|
openai_api_key = openaiApiKey;
|
||
|
openai_model_id = openaiModelId;
|
||
|
inherit
|
||
|
context
|
||
|
language
|
||
|
;
|
||
|
additional_instructions = additionalInstructions;
|
||
|
search_engine = searchEngine;
|
||
|
hooks = {
|
||
|
request_started = helpers.mkRaw hooks.requestStarted;
|
||
|
request_finished = helpers.mkRaw hooks.requestFinished;
|
||
|
};
|
||
|
inherit winhighlight;
|
||
|
}
|
||
|
// cfg.extraOptions;
|
||
|
in
|
||
|
mkIf cfg.enable {
|
||
|
extraPlugins = [cfg.package];
|
||
|
|
||
|
keymaps = filter (keymap: keymap != null) (
|
||
|
mapAttrsToList
|
||
|
(
|
||
|
action: value:
|
||
|
if isString value
|
||
|
then defaultKeymaps.${action} // {key = value;}
|
||
|
else value
|
||
|
)
|
||
|
cfg.keymaps
|
||
|
);
|
||
|
|
||
|
extraConfigLua = ''
|
||
|
require("wtf").setup(${helpers.toLuaObject setupOptions})
|
||
|
'';
|
||
|
};
|
||
|
}
|