Skip to content

Commit

Permalink
Export keymaps.accept_suggestion and dismiss_suggestion for remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondill committed Apr 30, 2023
1 parent 85a3209 commit d0bebf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
7 changes: 7 additions & 0 deletions lua/tabnine/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ local function valid_response(response)
end

function M.accept()
if not state.completions_cache then
return
end
M.clear()
local lines = utils.str_to_lines(state.rendered_completion)

Expand All @@ -31,10 +34,14 @@ function M.accept()
end

function M.clear()
if not state.completions_cache then
return
end
if state.cancel_completion then
state.cancel_completion()
end
state.debounce_timer:stop()

api.nvim_buf_clear_namespace(0, consts.tabnine_namespace, 0, -1)
end

Expand Down
28 changes: 12 additions & 16 deletions lua/tabnine/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ local state = require("tabnine.state")
local config = require("tabnine.config")
local completion = require("tabnine.completion")

function M.accept_suggestion()
vim.schedule(completion.accept)
end
function M.dismiss_suggestion()
vim.schedule(function()
completion.clear()
state.completions_cache = nil
end)
end

function M.setup()
local accept_keymap = config.get_config().accept_keymap
local dismiss_keymap = config.get_config().dismiss_keymap
vim.keymap.set("i", accept_keymap, function()
if not state.completions_cache then
return accept_keymap
end
vim.schedule(completion.accept)
end, { expr = true })

vim.keymap.set("i", dismiss_keymap, function()
if not state.completions_cache then
return dismiss_keymap
end
vim.schedule(function()
completion.clear()
state.completions_cache = nil
end)
end, { expr = true })
vim.keymap.set("i", accept_keymap, M.accept_suggestion, { expr = true })
vim.keymap.set("i", dismiss_keymap, M.dismiss_suggestion, { expr = true })
end

return M

0 comments on commit d0bebf0

Please sign in to comment.