copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.83k stars 128 forks source link

Possible bug: Conflict with pyim candidate display #13

Closed xqliu closed 2 years ago

xqliu commented 2 years ago
image

As per above image, there should be the first candidate of pyim "删除" displayed on the buffer, but current it displays the copilot suggestion and it hides pyim's candidate, this is not an issue when the candidate is only one or two Chinese character, but if we are inputing a very long sentence, then hide the whole candidate will be an issue.

zerolfx commented 2 years ago

Is it ok to disable Copilot completion temporarily if there are any candidates from pyim (or any incomplete input)? If so, I recommend you customize copilot-disable-predicates to solve the problem. Please let me know if the work-around works, and share your configuration if possible.

zerolfx commented 2 years ago

I am not a pyim user, but I took a look at pyim source code.

A possible solution (untested):

  (customize-set-variable 'copilot-disable-predicates
                          '((lambda ()
                              (and (boundp 'pyim-preview-overlay)
                                   pyim-preview-overlay))))
zerolfx commented 2 years ago

Actually, it is not a bug. The reason behind the problem is that both pyim and copilot.el use overlays to provide inline previews, so they may overwrite each other. And I believe temporarily disabling Copilot when pyim is using overlay is the best solution.

xqliu commented 2 years ago

Thanks dude, have applied the setting and is testing on that, will offer feedback when confirm the issue has been fixed (or not) 👍

xqliu commented 2 years ago

Hi, Zerolfx,

Seems the copilot-disable-predicates is not been applied as per follow screenshot

image

The current overlay of pyim should be 好的,but seems the predict of copilot is display instead of pyim's candidate

Here are my settings regarding copilot.el

(use-package! editorconfig
  :config
  (editorconfig-mode 1))

(use-package! copilot
  :config
   ; provide completion when typing
  (global-set-key (kbd "TAB") 'copilot-accept-completion)
  (global-set-key (kbd "C-c c") 'copilot-accept-completion)
  (global-set-key (kbd "C-c n") 'copilot-next-completion)
  (global-set-key (kbd "C-c p") 'copilot-previous-completion)
  (global-set-key (kbd "C-c w") 'copilot-accept-completion-by-word)
  (customize-set-variable 'copilot-enable-predicates '(evil-insert-state-p))
  (customize-set-variable 'copilot-disable-predicates
                          '((lambda ()
                              (and (boundp 'pyim-preview-overlay)
                                   pyim-preview-overlay))))
  (add-hook 'post-command-hook (lambda ()
                                 (copilot-clear-overlay)
                                 (when (evil-insert-state-p)
                                   (copilot-complete))))
  )

(provide 'copilot-config)
zerolfx commented 2 years ago

copilot-disable-predicates only works in copilot-mode. See readme for more information.

zerolfx commented 2 years ago

After trying with pyim, I found another problem: post-command-hook is not called when inputting with pyim, so the copilot overlay can't be cleared timely.

zerolfx commented 2 years ago

After trying with pyim, I found another problem: post-command-hook is not called when inputting with pyim, so the copilot overlay can't be cleared timely.

So I use advice to clear copilot overlay when typing in pyim.

(advice-add 'pyim-self-insert-command :after 'copilot-clear-overlay)
zerolfx commented 2 years ago

Another possible solution is to disable copilot whenever pyim is enabled:

(customize-set-variable 'copilot-disable-predicates '(pyim-process-input-chinese-p))
xqliu commented 2 years ago

Thanks :) I have applied this fix and is testing the behaviour

After trying with pyim, I found another problem: post-command-hook is not called when inputting with pyim, so the copilot overlay can't be cleared timely.

So I use advice to clear copilot overlay when typing in pyim.

(advice-add 'pyim-self-insert-command :after 'copilot-clear-overlay)
xqliu commented 2 years ago

Can treat this bug as fixed.

Thanks for your work :)