zbirenbaum / copilot.lua

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

copilot setting wrong start line on InsertLeave events #267

Closed danielreis1 closed 2 months ago

danielreis1 commented 5 months ago

I have the following functions to set a mark when entering insert mode and when leaving insert mode read that mark, count lines and perform a change on the lines

-- required to add the mark on entering insert mode
--  for M.perform_change_on_insert_mode to work properly
function M.set_mark_for_insert_leave_event()
  vim.api.nvim_command("normal! mm")
end

function M.perform_change_on_insert_mode()
  local start_line = vim.fn.getpos("'m")[2]
  local end_line = vim.api.nvim_win_get_cursor(0)[1]
  ...
end

the problem is: copilot appears to leave insert mode in a strange way: if I set a print on start_line and end_line, after I accept a suggestion, the start line will be set at 0 and end line at the line it is supposed to be, which is fine, the problem appears to be the start line really. this behavior may mess up insertLeave event hooks. I was wondering if there is a special reason it must be this way.

my config: (in case there is some problem here)

require('copilot').setup({
  panel = {
    enabled = false,
    auto_refresh = false,
    keymap = {
      jump_prev = "[[",
      jump_next = "]]",
      accept = "<CR>",
      refresh = "gr",
      open = "<leader>cop"
    },
    layout = {
      position = "bottom", -- | top | left | right
      ratio = 0.4
    },
  },
  suggestion = {
    enabled = true,
    auto_trigger = true,
    debounce = 75,
    keymap = {
      --accept = "<A-s>",
      accept_word = false,
      accept_line = false,
      next = "<A-a>",
      prev = "<A-d>",
      dismiss = "<A-q>",
    },
  },
  filetypes = {
    yaml = false,
    markdown = false,
    help = false,
    gitcommit = false,
    gitrebase = false,
    hgcommit = false,
    svn = false,
    cvs = false,
    ["."] = false,
  },
  copilot_node_command = 'node', -- Node.js version must be > 18.x
  server_opts_overrides = {},
})

require('copilot_cmp').setup({})
--require("copilot.suggestion").accept(modifier)

vim.keymap.set({ 'i', 'n' }, "<A-s>",[[<cmd>lua require('copilot.suggestion').accept()<CR><Esc>]])
danielreis1 commented 2 months ago

it was that last line I guess fixed with: image