zbirenbaum / copilot.lua

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

Suggestion doesn't always disappear when leaving insert mode #190

Closed MariaSolOs closed 1 year ago

MariaSolOs commented 1 year ago

It rarely happens, but sometimes Copilot will still display the last suggestion when leaving insert mode. I fixed it with a simple autocommand for InsertLeave, but I think there's a missing logic for that here.

MunifTanjim commented 1 year ago

Reproduction steps would really help.

I fixed it with a simple autocommand for InsertLeave

What did you do inside that autocmd?

MariaSolOs commented 1 year ago

@MunifTanjim unfortunately I haven't been able to pinpoint exactly when it happens :( I apologize for the lack of information. I do use the vim.b.copilot_suggestion_hidden toggling described in the README to make it not step over completions, so maybe something is going out of sync there?

What did you do inside that autocmd?

Just this:

local dismiss = function()
  if copilot.is_visible() then copilot.dismiss() end
end

vim.api.nvim_create_autocmd('InsertLeave', {
  pattern = '*',
  callback = dismiss,
})
MariaSolOs commented 1 year ago

@MunifTanjim Would you be against me preparing a PR for this? :)

MunifTanjim commented 1 year ago

I'm not against a PR. But I'd like to reproduce it with minimal config first... You know, just to rule out that it is indeed a bug caused by this plugin, and not by your config or some other plugins.

MunifTanjim commented 1 year ago

Can you please create a repro.lua file:

local root = vim.fn.fnamemodify(vim.trim(vim.fn.system("git rev-parse --show-toplevel")), ":p") .. ".repro"
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
  "folke/tokyonight.nvim",
  {
    "zbirenbaum/copilot.lua",
    opts = {},
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd("colorscheme tokyonight")

If it's reproducible, share the modified repro.lua file?

MariaSolOs commented 1 year ago

Found the repro! :) It doesn't require any special setup, just use the <C-c> mapping to exit insert mode.

Now I understand why this doesn't dismiss the suggestion: According to the docs, "it doesn't trigger the InsertLeave event", which this plugin relies on.

MariaSolOs commented 1 year ago

That also means that my auto command above doesn't work lol.

MunifTanjim commented 1 year ago

So it's the same as https://github.com/zbirenbaum/copilot.lua/issues/179#issuecomment-1586132731... In that case, it's an expected behavior.

MariaSolOs commented 1 year ago

That's fair. I'll close this then.