zbirenbaum / copilot.lua

Fully featured & enhanced replacement for copilot.vim complete with API for interacting with Github Copilot
MIT License
2.43k stars 65 forks source link

The <Tab> keymap for accepting suggestion fails to insert a tabulation when there is no suggestion available. #217

Closed sebui closed 8 months ago

sebui commented 8 months ago

When the accept function is mapped to the <Tab> keymap, tabulation is not inserted when there is no suggestion available. Unlike github/copilot.vim, copilot.nvim effectively inserts a tab even when there is no suggestion available.

The cause of this problem lies in the early void return statement found in all accept functions:

https://github.com/zbirenbaum/copilot.lua/blob/1a8032ae496916ccc7a7a52ee79194fbef29f462/lua/copilot/suggestion.lua#L444-L447

A potential solution to this issue, although it requires further testing to ensure there are no unintended side effects, could involve making the following code modification:

  if not suggestion or vim.fn.empty(suggestion.text) == 1 then
    local key = config.get("suggestion").keymap.accept
    key = vim.api.nvim_replace_termcodes(key, true, false, true)
    vim.fn.feedkeys(key, "n")
    return
  end
MunifTanjim commented 8 months ago

This is expected behavior. Check:

sebui commented 8 months ago

Oh sorry did not see those threads