copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.71k stars 122 forks source link

Warning (copilot): copilot--infer-indentation-offset found no mode-specific indentation offset. #249

Closed bersace closed 5 months ago

bersace commented 5 months ago

Hi,

Thanks for maintaining copilot.el, it's very useful.

I'm using copilot for Golang within Doom Emacs. I have two issues:

First, often, a warning about infer-indentation pops. Even in file already indented. Actually, Go indentation is pretty standard to 4 spaces.

Warning (copilot): copilot--infer-indentation-offset found no mode-specific indentation offset.

How to handle this ?

Second, some times, the TAB completion stops working. I didn't found any relevant message in Messages. copilot shows a suggestion, but typing TAB just write a plain TAB char instead of accepting the suggestion. Do you have a clue ?

Here is my configuration:

# packages.el
(package! copilot
  :recipe (:host github :repo "copilot-emacs/copilot.el" :files ("*.el" "dist")))
# init.el
(doom! :input
       ;;chinese
       ;;japanese

       :completion
       (company +childframe)           ; the ultimate code completion backend
...
# config.el
;; 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)))
$ \emacs --version
GNU Emacs 29.2.50
Development version 77f5d4d523a4 on HEAD branch; build date 2024-01-29.
Copyright (C) 2024 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Running as daemon, with pure-GTK on Wayland, Linux.

Regards, Étienne

emil-vdw commented 5 months ago

First, often, a warning about infer-indentation pops. Even in file already indented. Actually, Go indentation is pretty standard to 4 spaces.

Indentation is not inferred based on what's in the file but based on the major mode. Disable the warning (copilot-indent-offset-warning-disable) or add a value for the major mode you are using (copilot-indentation-alist).

Second, some times, the TAB completion stops working. I didn't found any relevant message in Messages. copilot shows a suggestion, but typing TAB just write a plain TAB char instead of accepting the suggestion. Do you have a clue ?

Could you try the solution for Doom emacs as described in the readme?

bersace commented 5 months ago

Hello @emil-vdw , thanks for your quick answer !

Indentation is not inferred based on what's in the file but based on the major mode. Disable the warning (copilot-indent-offset-warning-disable) or add a value for the major mode you are using (copilot-indentation-alist).

I don't master enought ELisp. (add-to-list 'copilot-indentation-alist '(go-mode 4)) triggers Error running timer ‘copilot--post-command-debounce’: (wrong-type-argument sequencep 4) [5 times]. I disabled warning for now.

Second, some times, the TAB completion stops working. I didn't found any relevant message in Messages. copilot shows a suggestion, but typing TAB just write a plain TAB char instead of accepting the suggestion. Do you have a clue ?

Could you try the solution for Doom emacs as described in the readme?

I missed this, thanks !

Also, C-TAB did workaround this conflict. It's seems to work properly with this workaround.

I'm closing. Feel free to suggest how to customize copilot-indentation-alist or point me a doc I mised.

You're awesome.

emil-vdw commented 5 months ago

You are welcome! When in doubt you can always use M-x customize-group RET copilot RET but this should work:

(add-to-list
 'copilot-indentation-alist
 '(go-mode 4))
bersace commented 5 months ago

You are welcome! When in doubt you can always use M-x customize-group RET copilot RET but this should work:

(add-to-list
 'copilot-indentation-alist
 '(go-mode 4))

Ok, the invocation was right, but not at the right place. Thanks for the confirmation.

kelvie commented 5 months ago

After setting this for org-mode, I get:

Error running timer ‘copilot--post-command-debounce’: (wrong-type-argument symbolp '2) [2 times]

And also basically all Go code actually uses tabs, and not 4 spaces, that's what gofmt will do to your code btw.

bersace commented 4 months ago

First, often, a warning about infer-indentation pops. Even in file already indented. Actually, Go indentation is pretty standard to 4 spaces.

Indentation is not inferred based on what's in the file but based on the major mode. Disable the warning (copilot-indent-offset-warning-disable) or add a value for the major mode you are using (copilot-indentation-alist).

Second, some times, the TAB completion stops working. I didn't found any relevant message in Messages. copilot shows a suggestion, but typing TAB just write a plain TAB char instead of accepting the suggestion. Do you have a clue ?

Could you try the solution for Doom emacs as described in the readme?

The issue with this workaround, is that it break TAB or any other feature like indentation on any buffer with copilot enabled. How to determine whether a copilot suggestion is proposed ?

Something like:

(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)
            (copilot-has-suggestion-on-screen) ; HERE !!
             ;; 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))