copilot-emacs / copilot.el

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

TAB sometimes doesn't work in Doom Emacs #193

Closed jacky-xbb closed 9 months ago

jacky-xbb commented 11 months ago

I follow the instructions to config my doom

(package! copilot
  :recipe (:host github :repo "zerolfx/copilot.el" :files ("*.el" "dist")))

;; accept completion from copilot and fallback to company
(use-package! copilot
  :hook (prog-mode . copilot-mode)
  :bind (:map copilot-completion-map
              ("<tab>" . 'copilot-accept-completion)
              ("TAB" . 'copilot-accept-completion)
              ("C-TAB" . 'copilot-accept-completion-by-word)
              ("C-<tab>" . 'copilot-accept-completion-by-word)))

I use TAB to complete the code, and I found it sometimes works, and sometimes it doesn't work. Does anybody know the reason?

katafrakt commented 11 months ago

I have similar experience. Unfortunately, I don't know the reason, but I suspect that it conflicts with a language server's completion somehow sometimes.

jacky-xbb commented 11 months ago

I think so. And I found a way to bypass this problem. You can use other key binds instead of TAB.

i-oliva commented 11 months ago

I have the same issue, pretty annoying tbh...

emil-vdw commented 11 months ago

I also suspect that it is bound to some other completion framework.

With the configuration above applied, what is the output of 'C-x k ' (or M-x helpful-key )?

i-oliva commented 11 months ago

it's evil getting in the way, I fixed it like this

;; accept completion from copilot and fallback to company
(use-package! copilot
  :hook (prog-mode . copilot-mode)
  :bind (:map copilot-completion-map
              ("<tab>" . 'copilot-accept-completion)
              ("TAB" . 'copilot-accept-completion)
              ("C-TAB" . 'copilot-accept-completion-by-word)
              ("C-<tab>" . 'copilot-accept-completion-by-word)))

(after! (evil copilot)
  ;; Define the custom function that either accepts the completion or does the default behavior
  (defun my/copilot-tab-or-default ()
    (interactive)
    (if (and (bound-and-true-p copilot-mode)
             ;; Add any other conditions to check for active copilot suggestions if necessary
             )
        (copilot-accept-completion)
      (evil-insert 1))) ; Default action to insert a tab. Adjust as needed.

  ;; Bind the custom function to <tab> in Evil's insert state
  (evil-define-key 'insert 'global (kbd "<tab>") 'my/copilot-tab-or-default))

lmk if that works :)

i-oliva commented 11 months ago

cc @jacky-xbb @katafrakt @emil-vdw

emil-vdw commented 9 months ago

@jacky-xbb I'm going to assume that @i-oliva's fix has worked? It might be worth while to update the Doom section in the readme.