Closed fpl9000 closed 1 year ago
I confirm that this should be considered a bug. I will fix it later.
@fpl9000 Can you verify the fix bcc0407? Though I can't distinguish any difference on my end.
The position of the user cursor is checked to ensure the completion is up-to-date, and after this patch, the doc version is checked instead.
Thanks for the fix, @zerolfx! It seems to help with my original issue (above), but some testing shows a different issue. To reproduce:
(setq copilot-idle-delay 5)
. This makes the issue easier to reproduce, but it also happens with a shorter delay time.(defun increment (n)
. Do NOT press ENTER
.)
is removed when the completion is shown. See screenshot below.)
.I re-added the verification of the user cursor in commit 15a698e and it should not be removed in my previous fix.
Confirming that fixes the issue for me. Thanks!
I have copilot-idle-delay set to 1 second, but completions are frequently offered within milliseconds after I type some characters. This is distracting and causes me to make typos due to the text on the screen changing near where I'm typing.
From reading the code, this seems to happen because:
copilot-idle-delay is the time between when Emacs becomes idle and a request is sent to the server.
The request is delayed using run-with-idle-timer in copilot--post-command, but once run-with-idle-timer is called, the user has copilot-idle-delay seconds (plus the request/response round-trip time) to continue typing, which happens frequently for me.
When the completion arrives from the server, it is displayed immediately, without regard for whether Emacs is idle or if the buffer has changed since the request was sent.
I would prefer that copilot--show-completion does NOT display the completion if the buffer has changed since the request was sent to the server. Of course, not everyone would prefer this, so maybe this can be disabled by default unless a user-visible variable is set to non-nil?
I'm currently implementing this with advice on copilot--get-completion that saves the current value of
(buffer-modified-tick)
in a buffer-local variable. Then, advice on copilot--show-completion checks whether(buffer-modified-tick)
is equal to that variable to know if the buffer has changed since the request was sent. If the buffer has changed, the completion is not shown, otherwise it is.If you don't want to implement this behavior, my advice works for me, but I thought others might like to opt-in to this behavior. Also, I'm willing to implement this (and submit a pull request) if you'd prefer. Let me know.
Thanks for taking the time to read this.
-- Fran