Skip to content

Commit

Permalink
plugins/wtf: init
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Dec 18, 2023
1 parent b3fb1c4 commit 309e564
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
./lsp/lsp-lines.nix
./lsp/nvim-lightbulb.nix
./lsp/trouble.nix
./lsp/wtf.nix

./none-ls

Expand Down
124 changes: 124 additions & 0 deletions plugins/lsp/wtf.nix
Original file line number Diff line number Diff line change
@@ -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;

This comment has been minimized.

Copy link
@tbaumann

tbaumann Dec 19, 2023

error: attribute 'wtf-nvim' missing

main is currently broken.

This comment has been minimized.

Copy link
@GaetanLepage

GaetanLepage Dec 20, 2023

Author Member

wtf-nvim has been added very recently on the nixos-unstable and nixpkgs-unstable channels.
Make sure to update your nixpkgs revision.

This comment has been minimized.

Copy link
@tbaumann

tbaumann Dec 20, 2023

I was less than 2 weeks behind I think. :)
Sorry for the bother

This comment has been minimized.

Copy link
@GaetanLepage

GaetanLepage Dec 20, 2023

Author Member

Now worry !


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 changes: 39 additions & 0 deletions tests/test-sources/plugins/lsp/wtf.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
}

0 comments on commit 309e564

Please sign in to comment.