mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 19:46:06 +01:00
plugins/wtf: migrate to mkNeovimPlugin
This commit is contained in:
parent
2ad8d87e42
commit
c660702482
4 changed files with 102 additions and 172 deletions
|
|
@ -52,8 +52,6 @@
|
||||||
keymapOptions = [
|
keymapOptions = [
|
||||||
options.keymaps
|
options.keymaps
|
||||||
options.keymapsOnEvents
|
options.keymapsOnEvents
|
||||||
options.plugins.wtf.keymaps.ai
|
|
||||||
options.plugins.wtf.keymaps.search
|
|
||||||
# NOTE: lsp `diagnostic` and `lspBuf` don't use `mapOptionSubmodule` yet
|
# NOTE: lsp `diagnostic` and `lspBuf` don't use `mapOptionSubmodule` yet
|
||||||
# So we only need `lua` deprecation in lsp's `extra` option
|
# So we only need `lua` deprecation in lsp's `extra` option
|
||||||
options.plugins.lsp.keymaps.extra
|
options.plugins.lsp.keymaps.extra
|
||||||
|
|
|
||||||
|
|
@ -1,149 +1,21 @@
|
||||||
{
|
{ lib, ... }:
|
||||||
lib,
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
helpers,
|
name = "wtf";
|
||||||
config,
|
package = "wtf-nvim";
|
||||||
pkgs,
|
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||||
...
|
|
||||||
}:
|
|
||||||
with lib;
|
|
||||||
let
|
|
||||||
cfg = config.plugins.wtf;
|
|
||||||
|
|
||||||
defaultKeymaps = {
|
# TODO: introduced 2025-10-11: remove after 26.05
|
||||||
ai = {
|
inherit (import ./deprecations.nix lib) deprecateExtraOptions optionsRenamedToSettings imports;
|
||||||
key = "gw";
|
|
||||||
mode = [
|
|
||||||
"n"
|
|
||||||
"x"
|
|
||||||
];
|
|
||||||
action.__raw = "require('wtf').ai";
|
|
||||||
};
|
|
||||||
|
|
||||||
search = {
|
settingsExample = {
|
||||||
key = "gW";
|
popup_type = "popup";
|
||||||
mode = "n";
|
providers.openai = {
|
||||||
action.__raw = "require('wtf').search";
|
api_key = lib.nixvim.nestedLiteralLua "vim.env.OPENAI_API_KEY";
|
||||||
};
|
model_id = "gpt-3.5-turbo";
|
||||||
|
|
||||||
history = {
|
|
||||||
key = "wh";
|
|
||||||
mode = "n";
|
|
||||||
action.__raw = "require('wtf').history";
|
|
||||||
};
|
|
||||||
|
|
||||||
grep_history = {
|
|
||||||
key = "wg";
|
|
||||||
mode = "n";
|
|
||||||
action.__raw = "require('wtf').grep_history";
|
|
||||||
};
|
};
|
||||||
|
context = true;
|
||||||
|
language = "english";
|
||||||
|
search_engine = "phind";
|
||||||
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder";
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
(lib.mkRemovedOptionModule [ "plugins" "wtf" "context" ] ''
|
|
||||||
context is no longer supported, please remove it from your config
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
|
|
||||||
options = {
|
|
||||||
plugins.wtf = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
|
||||||
enable = mkEnableOption "wtf.nvim";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "wtf.nvim" {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"wtf-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
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.";
|
|
||||||
}
|
|
||||||
) defaultKeymaps;
|
|
||||||
|
|
||||||
popupType =
|
|
||||||
helpers.defaultNullOpts.mkEnumFirstDefault
|
|
||||||
[
|
|
||||||
"popup"
|
|
||||||
"horizontal"
|
|
||||||
"vertical"
|
|
||||||
]
|
|
||||||
''
|
|
||||||
Default AI popup type.
|
|
||||||
'';
|
|
||||||
|
|
||||||
openaiApiKey = helpers.defaultNullOpts.mkStr null ''
|
|
||||||
An alternative way to set your API key.
|
|
||||||
'';
|
|
||||||
|
|
||||||
openaiModelId = helpers.defaultNullOpts.mkStr "gpt-3.5-turbo" "ChatGPT Model.";
|
|
||||||
|
|
||||||
language = helpers.defaultNullOpts.mkStr "english" ''
|
|
||||||
Set your preferred language for the response.
|
|
||||||
'';
|
|
||||||
|
|
||||||
additionalInstructions = helpers.mkNullOrOption types.str "Any additional instructions.";
|
|
||||||
|
|
||||||
searchEngine = helpers.defaultNullOpts.mkEnumFirstDefault [
|
|
||||||
"google"
|
|
||||||
"duck_duck_go"
|
|
||||||
"stack_overflow"
|
|
||||||
"github"
|
|
||||||
] "Default search engine.";
|
|
||||||
|
|
||||||
hooks = {
|
|
||||||
requestStarted = helpers.defaultNullOpts.mkLuaFn "nil" "Callback for request start.";
|
|
||||||
|
|
||||||
requestFinished = helpers.defaultNullOpts.mkLuaFn "nil" "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;
|
|
||||||
providers = {
|
|
||||||
openai = {
|
|
||||||
model_id = openaiModelId;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
inherit language;
|
|
||||||
additional_instructions = additionalInstructions;
|
|
||||||
search_engine = searchEngine;
|
|
||||||
hooks = {
|
|
||||||
request_started = hooks.requestStarted;
|
|
||||||
request_finished = hooks.requestFinished;
|
|
||||||
};
|
|
||||||
inherit winhighlight;
|
|
||||||
}
|
|
||||||
// cfg.extraOptions;
|
|
||||||
in
|
|
||||||
mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
keymaps = filter (keymap: keymap != null) (attrValues cfg.keymaps);
|
|
||||||
|
|
||||||
extraConfigLua = ''
|
|
||||||
require("wtf").setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
55
plugins/by-name/wtf/deprecations.nix
Normal file
55
plugins/by-name/wtf/deprecations.nix
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
lib: {
|
||||||
|
imports =
|
||||||
|
let
|
||||||
|
basePluginPath = [
|
||||||
|
"plugins"
|
||||||
|
"wtf"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(lib.mkRemovedOptionModule
|
||||||
|
(
|
||||||
|
basePluginPath
|
||||||
|
++ [
|
||||||
|
"keymaps"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
''
|
||||||
|
Use nixvim's top-level `keymaps` option to manually declare your 'wtf-nvim' keymaps.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(lib.mkRemovedOptionModule (basePluginPath ++ [ "context" ]) ''
|
||||||
|
context is no longer supported, please remove it from your config.
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
{
|
||||||
|
old = "openaiModelId";
|
||||||
|
new = [
|
||||||
|
"providers"
|
||||||
|
"openai"
|
||||||
|
"model_id"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
old = "openaiApiKey";
|
||||||
|
new = [
|
||||||
|
"providers"
|
||||||
|
"openai"
|
||||||
|
"api_key"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ map (lib.splitString ".") [
|
||||||
|
"popupType"
|
||||||
|
"language"
|
||||||
|
"additionalInstructions"
|
||||||
|
"searchEngine"
|
||||||
|
"hooks.requestStarted"
|
||||||
|
"hooks.requestFinished"
|
||||||
|
"winhighlight"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
empty = {
|
empty = {
|
||||||
plugins.wtf.enable = true;
|
plugins.wtf.enable = true;
|
||||||
|
|
@ -7,35 +8,39 @@
|
||||||
plugins.wtf = {
|
plugins.wtf = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
keymaps = {
|
settings = {
|
||||||
ai.key = "gw";
|
popup_type = "popup";
|
||||||
search = {
|
providers.openai = {
|
||||||
mode = [
|
api_key = lib.nixvim.mkRaw "vim.env.OPENAI_API_KEY";
|
||||||
"n"
|
model_id = "gpt-3.5-turbo";
|
||||||
"x"
|
|
||||||
];
|
|
||||||
options.desc = "Search diagnostic with Google";
|
|
||||||
};
|
};
|
||||||
|
language = "english";
|
||||||
|
search_engine = "phind";
|
||||||
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder";
|
||||||
};
|
};
|
||||||
popupType = "popup";
|
};
|
||||||
openaiApiKey = null;
|
};
|
||||||
openaiModelId = "gpt-3.5-turbo";
|
|
||||||
language = "english";
|
defaults = {
|
||||||
additionalInstructions = "Hello world !";
|
plugins.wtf = {
|
||||||
searchEngine = "google";
|
enable = true;
|
||||||
hooks = {
|
|
||||||
requestStarted = ''
|
settings = {
|
||||||
function()
|
additional_instructions = null;
|
||||||
vim.cmd("hi StatusLine ctermbg=NONE ctermfg=yellow")
|
chat_dir = lib.nixvim.mkRaw "vim.fn.stdpath('data'):gsub('/$', \"\") .. '/wtf/chats'";
|
||||||
end
|
language = "english";
|
||||||
'';
|
picker = "telescope";
|
||||||
requestFinished = ''
|
popup_type = "horizontal";
|
||||||
vim.schedule_wrap(function()
|
provider = "openai";
|
||||||
vim.cmd("hi StatusLine ctermbg=NONE ctermfg=NONE")
|
search_engine = "google";
|
||||||
end)
|
# Extracting the default value would be annoying
|
||||||
'';
|
# providers = create_provider_defaults()
|
||||||
|
hooks = {
|
||||||
|
request_started = null;
|
||||||
|
request_finished = null;
|
||||||
|
};
|
||||||
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder";
|
||||||
};
|
};
|
||||||
winhighlight = "Normal:Normal,FloatBorder:FloatBorder";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue