diff --git a/modules/assistant/tabnine/config.nix b/modules/assistant/tabnine/config.nix index d925ed05..b959495c 100644 --- a/modules/assistant/tabnine/config.nix +++ b/modules/assistant/tabnine/config.nix @@ -10,13 +10,43 @@ in { config = mkIf cfg.enable { vim.startPlugins = ["tabnine-nvim"]; + vim.maps.insert = mkMerge [ + (mkExprBinding cfg.mappings.accept '' + function() + local state = require("tabnine.state") + local completion = require("tabnine.completion") + + if not state.completions_cache then + return "${builtins.toJSON cfg.mappings.accept}" + end + + vim.schedule(completion.accept) + end + '' "orzel") + (mkExprBinding cfg.mappings.dismiss '' + function() + local state = require("tabnine.state") + local completion = require("tabnine.completion") + + if not state.completions_cache then + return "${builtins.toJSON cfg.mappings.dismiss}" + end + + vim.schedule(function() + completion.clear() + state.completions_cache = nil + end) + end + '' "orzel") + ]; + vim.luaConfigRC.tabnine-nvim = nvim.dag.entryAnywhere '' require('tabnine').setup({ disable_auto_comment = ${boolToString cfg.disable_auto_comment}, - accept_keymap = ${cfg.accept_keymap}, - dismiss_keymap = ${cfg.dismiss_keymap}, + accept_keymap = null, + dismiss_keymap = null, debounce_ms = ${cfg.debounce_ms}, - execlude_filetypes = ${cfg.execlude_filetypes}, + exclude_filetypes = ${cfg.exclude_filetypes}, }) ''; }; diff --git a/modules/assistant/tabnine/tabnine.nix b/modules/assistant/tabnine/tabnine.nix index f0674cbb..b977cefb 100644 --- a/modules/assistant/tabnine/tabnine.nix +++ b/modules/assistant/tabnine/tabnine.nix @@ -1,8 +1,4 @@ -{ - config, - lib, - ... -}: +{lib, ...}: with lib; with builtins; { options.vim.assistant.tabnine = { @@ -14,16 +10,9 @@ with builtins; { description = "Disable auto comment"; }; - accept_keymap = mkOption { - type = types.str; - default = ""; - description = "Accept keymap"; - }; - - dismiss_keymap = mkOption { - type = types.str; - default = ""; - description = "Dismiss keymap"; + mappings = { + accept = mkMappingOption "Accept [Tabnine]" ""; + dismiss = mkMappingOption "Dismiss [Tabnine]" ""; }; debounce_ms = mkOption { @@ -32,10 +21,10 @@ with builtins; { description = "Debounce ms"; }; - execlude_filetypes = mkOption { + exclude_filetypes = mkOption { type = types.listOf types.str; default = ["TelescopePrompt" "NvimTree" "alpha"]; - description = "Execlude filetypes"; + description = "Exclude filetypes"; }; }; }