copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.79k stars 126 forks source link

Negative user experience related to copilot-idle-delay #139

Closed fpl9000 closed 1 year ago

fpl9000 commented 1 year ago

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:

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

zerolfx commented 1 year ago

I confirm that this should be considered a bug. I will fix it later.

zerolfx commented 1 year ago

@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.

fpl9000 commented 1 year ago

Thanks for the fix, @zerolfx! It seems to help with my original issue (above), but some testing shows a different issue. To reproduce:

Screenshot of issue

zerolfx commented 1 year ago

I re-added the verification of the user cursor in commit 15a698e and it should not be removed in my previous fix.

fpl9000 commented 1 year ago

Confirming that fixes the issue for me. Thanks!