copilot.lua icon indicating copy to clipboard operation
copilot.lua copied to clipboard

lingering ghost text

Open Aqothy opened this issue 8 months ago • 4 comments

Ghost text is left behind on screen and not cleared when in normal mode (think this might have something to do with smart/auto indentation). To reproduce this error edit a piece of text that has multiple indentation levels, press o to insert on next line, wait for suggestion to appear, press esc to go normal mode, press I for insert mode, wait for ghost text to appear, then press backspace once to delete, now your cursor will be on previous line, press esc and there will be ghost text left behind on screen

Image

Aqothy avatar May 10 '25 20:05 Aqothy

Thank you I was able to replicate it :)

AntoineGS avatar May 14 '25 19:05 AntoineGS

Went to work on this and I cannot seem to replicate it anymore. I am starting to think it was an issue on the LSP side that got resolved in an update 🤷‍♂️ If you update to the latest version are you able to replicate it?

AntoineGS avatar May 23 '25 18:05 AntoineGS

Went to work on this and I cannot seem to replicate it anymore. I am starting to think it was an issue on the LSP side that got resolved in an update 🤷‍♂️ If you update to the latest version are you able to replicate it?

Update to latest copilot plugin? I'm on the latest commit rn and still able to reproduce the error, it's actually gotten worse for me lol, the ghost text somehow turned actually syntax highlighted ghost text, but when I redraw the screen the text goes away. Btw this issue happens when expandtab is set to false, if expandtab is true this issue doesn't happen to me.

Aqothy avatar May 24 '25 06:05 Aqothy

I am also seeing this

I can replicate that virtual text will not go away when exiting insert with C-c during a suggestion

whoop-t avatar Jun 11 '25 17:06 whoop-t

Same here. Rebinding C-c so that it also dismisses the current suggestion before exiting insert mode seems to be one possible workaround:

local copilot_suggestion = require("copilot.suggestion")

vim.keymap.set('i', '<C-c>', function()
  if copilot_suggestion.is_visible() then
    copilot_suggestion.dismiss()
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
  else
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, false, true), 'n', true)
  end
end, { noremap = true, silent = true, desc = "Dismiss Copilot suggestion and exit insert mode" })

One guess why C-c is an issue (and not regular escape) is because C-c does not trigger the InsertLeave autocommand event which is probably what's used to clean up the ghost text.

greywolve avatar Jul 23 '25 15:07 greywolve

I also see this (not using C-c).

boborbt avatar Aug 22 '25 22:08 boborbt

@greywolve yeah C-c is an 'abort' keymap so a lot of plugins probably have problems with it. @boborbt do you have instructions as to how to replicate it? I have been unable to replicate this based on the original steps for a while now.

AntoineGS avatar Aug 28 '25 01:08 AntoineGS

@greywolve yeah C-c is an 'abort' keymap so a lot of plugins probably have problems with it. @boborbt do you have instructions as to how to replicate it? I have been unable to replicate this based on the original steps for a while now.

here's a video, if you have vim.opt.expandtab = false this will happen following the steps I originally mentioned

Image

Aqothy avatar Aug 28 '25 22:08 Aqothy

Awesome the expandtab was the missing link!

AntoineGS avatar Aug 29 '25 00:08 AntoineGS

Well that was one hell of an investigation. Turns out it's a bug in NeoVim with the inline extmarks. I have created an issue and will update this when resolved.

AntoineGS avatar Aug 29 '25 02:08 AntoineGS

Looks like control chars are not supported with inline extmarks, I have added a workaround which seems to resolve it.

AntoineGS avatar Aug 29 '25 13:08 AntoineGS