Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copilot setting wrong start line on InsertLeave events #267

Closed
danielreis1 opened this issue Feb 4, 2024 · 1 comment
Closed

copilot setting wrong start line on InsertLeave events #267

danielreis1 opened this issue Feb 4, 2024 · 1 comment

Comments

@danielreis1
Copy link

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
Copy link
Author

it was that last line I guess
fixed with:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant