minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
573 stars 20 forks source link

Extra chars with `cape-wrap-buster` #81

Closed lynnux closed 1 year ago

lynnux commented 1 year ago

Hi @minad , thanks for new tips in https://github.com/minad/corfu/wiki#1-mode-use-eglot-to-provide-continuously-updated-candidates, I really need this feature for code completion. But I got error message Args out of range: 0, 0 when I choose item in front of which has a round dot. like this: 09b9a2562777203ce430909852a642b if I press enter, the output will be: e54f59f8187dce92679be4728ff2688 There should not have a round dot before ICreateErrorInfo, I think this error is from this config:

(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)

If I comment out (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster), there still have round dot in corfu items, but will not get error message Args out of range: 0, 0 and the output will also not have round dot.

More details if M-x with toggle-debug-on-error: image

And this is the minmal config:


(add-to-list 'load-path
         "~/.emacs.d/packages")
(eval-when-compile
  (add-to-list 'load-path "~/.emacs.d/packages/use-package/use-package-master")
  (condition-case nil
      (require 'use-package)
    (error (update-all-packages))) ;; 首次检查是否解压,之后还是手动更新包吧
  )

(use-package compat
      :load-path "~/.emacs.d/packages/minibuffer/compat-main"
      :init
      (unless (functionp 'ensure-list)
        (defun ensure-list (object)
          ;; for 28.0.5
          (if (listp object)
              object
            (list object)))
        ))
(use-package corfu
  :load-path "~/.emacs.d/packages/corfu/corfu-main"
  :init
  (autoload 'cape-wrap-buster "corfu/cape" "" nil)
  (setq corfu-cycle t
        corfu-auto t
        corfu-auto-prefix 1
        corfu-preview-current nil ; 避免直接上屏,有时候输入完了要马上C-n/C-p,这时只需要按个C-g就可以了,而不需要再删除上屏的
        ;; corfu-auto-delay 0.2      ;; 避免输完后马上C-n/C-p也补全
        ;; corfu-quit-at-boundary nil ;; 可以用M-空格来分词
        corfu-quit-no-match t ;; 没有match时退出,不然有个No match影响操作
        )
  (add-to-list 'load-path "~/.emacs.d/packages/corfu/corfu-main/extensions")
  :config
  (global-corfu-mode t)
  )

(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)

Emacs version: "30.0.50", window 64bit, eglot with clangd, latest corfu and cape.

minad commented 1 year ago

Thanks for the report! Please check that f4ed6f198d5995e693bf452e875b2b09469fccfb fixes the issue for you.

lynnux commented 1 year ago

Thanks for the fix, it's OK when press Enter (corfu-insert), but get same output when press TAB (corfu-complete), but no error message Args out of range: 0, 0 anymore. It's still OK when press TAB to completion without cape.

minad commented 1 year ago

Thanks for confirming.

The problem with TAB seems to be here that Corfu doesn't call the :exit-function to fix the candidate. Ideally the backend wouldn't produce such invalid candidates which would require fixing afterwards. You can check why corfu--done is not called at one of the following locations in corfu-complete. corfu--done should then in turn call :exit-function which will fix the candidate.

https://github.com/minad/corfu/blob/5daeb9c5b76243ea5b2d6d3dd5692e4eefda4f4b/corfu.el#L1196

https://github.com/minad/corfu/blob/5daeb9c5b76243ea5b2d6d3dd5692e4eefda4f4b/corfu.el#L1204

https://github.com/minad/corfu/blob/5daeb9c5b76243ea5b2d6d3dd5692e4eefda4f4b/corfu.el#L1216

As you wrote above, the round dot issue is unrelated to this Cape issue.

If I comment out (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster), there still have round dot in corfu items, but will not get error message Args out of range: 0, 0 and the output will also not have round dot.

lynnux commented 1 year ago

Sorry, I'm not quite understanding the lisp code, I can only write some emacs lisp config code. But without cape, although corfu show round dot, the completion/output will not have round dot after Enter or 'TAB', so I think the items handled by cape-wrap-buster may have some little difference from original.

minad commented 1 year ago

Okay, please try the commit https://github.com/minad/cape/commit/12b157b0e3367504d4267c3b3977850e588e463e (separate branch) and let me know if this works.

lynnux commented 1 year ago

It's still the same that Enter ok and TAB not work. I don't quite unstand the difference between corfu-insert and corfu-complete, for me they like the same, a workaround is rebind TAB to corfu-insert:

    (define-key corfu-map (kbd "<tab>") 'corfu-insert)
    (define-key corfu-map (kbd "TAB") 'corfu-insert)

And I find out that: TAB will not have the round dot if the complition call yas-expand-snippet, like this: 1681440147634 but will have the round dot if don't call yas-expand-snippet, like this: 62f0aea86df1c6afe86840e22b0c338