mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-25 02:08:40 +02:00
plugins/wtf: init
This commit is contained in:
parent
b3fb1c4c81
commit
309e5644fc
3 changed files with 164 additions and 0 deletions
|
@ -77,6 +77,7 @@
|
||||||
./lsp/lsp-lines.nix
|
./lsp/lsp-lines.nix
|
||||||
./lsp/nvim-lightbulb.nix
|
./lsp/nvim-lightbulb.nix
|
||||||
./lsp/trouble.nix
|
./lsp/trouble.nix
|
||||||
|
./lsp/wtf.nix
|
||||||
|
|
||||||
./none-ls
|
./none-ls
|
||||||
|
|
||||||
|
|
124
plugins/lsp/wtf.nix
Normal file
124
plugins/lsp/wtf.nix
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
{
|
||||||
|
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})
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
39
tests/test-sources/plugins/lsp/wtf.nix
Normal file
39
tests/test-sources/plugins/lsp/wtf.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
empty = {
|
||||||
|
plugins.wtf.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
example = {
|
||||||
|
plugins.wtf = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
keymaps = {
|
||||||
|
ai = "gw";
|
||||||
|
search = {
|
||||||
|
mode = ["n" "x"];
|
||||||
|
options.desc = "Search diagnostic with Google";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
popupType = "popup";
|
||||||
|
openaiApiKey = null;
|
||||||
|
openaiModelId = "gpt-3.5-turbo";
|
||||||
|
context = true;
|
||||||
|
language = "english";
|
||||||
|
additionalInstructions = "Hello world !";
|
||||||
|
searchEngine = "google";
|
||||||
|
hooks = {
|
||||||
|
requestStarted = ''
|
||||||
|
function()
|
||||||
|
vim.cmd("hi StatusLine ctermbg=NONE ctermfg=yellow")
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
requestFinished = ''
|
||||||
|
vim.schedule_wrap(function()
|
||||||
|
vim.cmd("hi StatusLine ctermbg=NONE ctermfg=NONE")
|
||||||
|
end)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue