nix-community.nixvim/plugins/by-name/wtf/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
3.4 KiB
Nix
Raw Normal View History

2023-12-15 14:00:55 +01:00
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.wtf;
defaultKeymaps = {
ai = {
key = "gw";
mode = [
"n"
"x"
];
action.__raw = "require('wtf').ai";
2023-12-15 14:00:55 +01:00
};
search = {
key = "gW";
mode = "n";
action.__raw = "require('wtf').search";
2023-12-15 14:00:55 +01:00
};
history = {
key = "wh";
mode = "n";
action.__raw = "require('wtf').history";
};
grep_history = {
key = "wg";
mode = "n";
action.__raw = "require('wtf').grep_history";
};
2023-12-15 14:00:55 +01:00
};
in
{
options = {
plugins.wtf = lib.nixvim.neovim-plugin.extraOptionsOptions // {
2023-12-15 14:00:55 +01:00
enable = mkEnableOption "wtf.nvim";
2024-05-05 19:39:35 +02:00
package = lib.mkPackageOption pkgs "wtf.nvim" {
default = [
"vimPlugins"
"wtf-nvim"
];
};
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
keymaps = mapAttrs (
action: defaults:
helpers.mkNullOrOption' {
type =
with types;
coercedTo str (key: defaultKeymaps.${action} // { inherit key; }) (
helpers.keymaps.mkMapOptionSubmodule {
inherit defaults;
lua = true;
}
);
apply = v: if v == null then null else helpers.keymaps.removeDeprecatedMapAttrs v;
description = "Keymap for the ${action} action.";
}
2023-12-15 14:00:55 +01:00
) defaultKeymaps;
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
popupType =
2024-06-11 16:53:12 +01:00
helpers.defaultNullOpts.mkEnumFirstDefault
2023-12-15 14:00:55 +01:00
[
"popup"
"horizontal"
"vertical"
]
''
Default AI popup type.
'';
2024-05-05 19:39:35 +02:00
2024-06-11 16:53:12 +01:00
openaiApiKey = helpers.defaultNullOpts.mkStr null ''
2023-12-15 14:00:55 +01:00
An alternative way to set your API key.
'';
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
openaiModelId = helpers.defaultNullOpts.mkStr "gpt-3.5-turbo" "ChatGPT Model.";
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
context = helpers.defaultNullOpts.mkBool true "Send code as well as diagnostics.";
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
language = helpers.defaultNullOpts.mkStr "english" ''
Set your preferred language for the response.
'';
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
additionalInstructions = helpers.mkNullOrOption types.str "Any additional instructions.";
2024-05-05 19:39:35 +02:00
2024-06-11 16:53:12 +01:00
searchEngine = helpers.defaultNullOpts.mkEnumFirstDefault [
2023-12-15 14:00:55 +01:00
"google"
"duck_duck_go"
"stack_overflow"
"github"
2024-06-11 16:53:12 +01:00
] "Default search engine.";
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
hooks = {
requestStarted = helpers.defaultNullOpts.mkLuaFn "nil" "Callback for request start.";
2024-05-05 19:39:35 +02:00
requestFinished = helpers.defaultNullOpts.mkLuaFn "nil" "Callback for request finished.";
2023-12-15 14:00:55 +01:00
};
2024-05-05 19:39:35 +02:00
2023-12-15 14:00:55 +01:00
winhighlight = helpers.defaultNullOpts.mkStr "Normal:Normal,FloatBorder:FloatBorder" ''
Add custom colours.
2024-05-05 19:39:35 +02:00
'';
};
2023-12-15 14:00:55 +01:00
};
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 = hooks.requestStarted;
request_finished = hooks.requestFinished;
2023-12-15 14:00:55 +01:00
};
inherit winhighlight;
}
// cfg.extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
keymaps = filter (keymap: keymap != null) (attrValues cfg.keymaps);
2023-12-15 14:00:55 +01:00
extraConfigLua = ''
require("wtf").setup(${lib.nixvim.toLuaObject setupOptions})
2023-12-15 14:00:55 +01:00
'';
};
}