minad / corfu

:desert_island: corfu.el - COmpletion in Region FUnction
GNU General Public License v3.0
1.15k stars 43 forks source link

Corfu is broken using corfu-terminal #341

Closed illia-danko closed 1 year ago

illia-danko commented 1 year ago

Hello, found that the last commit (https://github.com/minad/corfu/commit/491e4ec33ed028172556a21ac43e649eeba36d1f) breaks the completion with:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p (#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)))
  posn-at-point((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)))
  popon-x-y-at-pos((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)))
  #f(compiled-function (cl--cnm pos off width lines &optional curr lo bar) "Show popup at OFF columns before POS.\n\nShow LINES, a list of lines.  Highlight CURRth line as current\nselection.  Show a vertical scroll bar of size BAR + 1 from LOth line.\n\nIf `corfu-terminal-disable-on-gui' is non-nil and  `display-graphic-p'\nreturns non-nil then call FN instead, where FN should be the original\ndefinition in Corfu." #<bytecode 0x7de1707d93a794c>)(#f(compiled-function (&rest cnm-args) #<bytecode 0x7ad64dd7f740b46>) (#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)) 0 24 (#("flag              \"flag\"" 0 1 (eglot--lsp-item (:label #("flag" 0 1 (eglot--lsp-item #9)) :kind 9 :detail "\"flag\"" :sortText "00001" :filterText "flag" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flag") :additionalTextEdits [(:range (:start ... :end ...) :newText "\"\n\11\"flag")]) face completions-common-part completion-score 0.75) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 18 24 (face font-lock-function-name-face)) #("flags     *pflag.FlagSet" 0 1 (eglot--lsp-item (:label #("flags" 0 1 (eglot--lsp-item #10)) :kind 6 :detail "*pflag.FlagSet" :preselect t :sortText "00000" :filterText "flags" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flags")) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 10 24 (face font-lock-function-name-face)) #("flate   \"compress/flate\"" 0 1 (eglot--lsp-item (:label #("flate" 0 1 (eglot--lsp-item #11)) :kind 9 :detail "\"compress/flate\"" :sortText "00002" :filterText "flate" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flate") :additionalTextEdits [(:range (:start ... :end ...) :newText "\n\11\"compress/flate\"")]) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 8 24 (face font-lock-function-name-face)) #("float32            Class" 0 1 (eglot--lsp-item (:label #("float32" 0 1 (eglot--lsp-item #12)) :kind 7 :sortText "00011" :filterText "float32" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float32")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face)) #("float64            Class" 0 1 (eglot--lsp-item (:label #("float64" 0 1 (eglot--lsp-item #13)) :kind 7 :sortText "00012" :filterText "float64" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float64")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face))) 0 nil 20)
  apply(#f(compiled-function (cl--cnm pos off width lines &optional curr lo bar) "Show popup at OFF columns before POS.\n\nShow LINES, a list of lines.  Highlight CURRth line as current\nselection.  Show a vertical scroll bar of size BAR + 1 from LOth line.\n\nIf `corfu-terminal-disable-on-gui' is non-nil and  `display-graphic-p'\nreturns non-nil then call FN instead, where FN should be the original\ndefinition in Corfu." #<bytecode 0x7de1707d93a794c>) #f(compiled-function (&rest cnm-args) #<bytecode 0x7ad64dd7f740b46>) ((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)) 0 24 (#("flag              \"flag\"" 0 1 (eglot--lsp-item (:label #("flag" 0 1 (eglot--lsp-item #11)) :kind 9 :detail "\"flag\"" :sortText "00001" :filterText "flag" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flag") :additionalTextEdits [(:range ... :newText "\"\n\11\"flag")]) face completions-common-part completion-score 0.75) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 18 24 (face font-lock-function-name-face)) #("flags     *pflag.FlagSet" 0 1 (eglot--lsp-item (:label #("flags" 0 1 (eglot--lsp-item #12)) :kind 6 :detail "*pflag.FlagSet" :preselect t :sortText "00000" :filterText "flags" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flags")) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 10 24 (face font-lock-function-name-face)) #("flate   \"compress/flate\"" 0 1 (eglot--lsp-item (:label #("flate" 0 1 (eglot--lsp-item #13)) :kind 9 :detail "\"compress/flate\"" :sortText "00002" :filterText "flate" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flate") :additionalTextEdits [(:range ... :newText "\n\11\"compress/flate\"")]) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 8 24 (face font-lock-function-name-face)) #("float32            Class" 0 1 (eglot--lsp-item (:label #("float32" 0 1 (eglot--lsp-item #14)) :kind 7 :sortText "00011" :filterText "float32" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "float32")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face)) #("float64            Class" 0 1 (eglot--lsp-item (:label #("float64" 0 1 (eglot--lsp-item #15)) :kind 7 :sortText "00012" :filterText "float64" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "float64")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face))) 0 nil 20))
  #f(compiled-function (&rest args) #<bytecode 0x5c46c93f194842c>)((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)) 0 24 (#("flag              \"flag\"" 0 1 (eglot--lsp-item (:label #("flag" 0 1 (eglot--lsp-item #8)) :kind 9 :detail "\"flag\"" :sortText "00001" :filterText "flag" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flag") :additionalTextEdits [(:range (:start ... :end ...) :newText "\"\n\11\"flag")]) face completions-common-part completion-score 0.75) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 18 24 (face font-lock-function-name-face)) #("flags     *pflag.FlagSet" 0 1 (eglot--lsp-item (:label #("flags" 0 1 (eglot--lsp-item #9)) :kind 6 :detail "*pflag.FlagSet" :preselect t :sortText "00000" :filterText "flags" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flags")) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 10 24 (face font-lock-function-name-face)) #("flate   \"compress/flate\"" 0 1 (eglot--lsp-item (:label #("flate" 0 1 (eglot--lsp-item #10)) :kind 9 :detail "\"compress/flate\"" :sortText "00002" :filterText "flate" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flate") :additionalTextEdits [(:range (:start ... :end ...) :newText "\n\11\"compress/flate\"")]) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 8 24 (face font-lock-function-name-face)) #("float32            Class" 0 1 (eglot--lsp-item (:label #("float32" 0 1 (eglot--lsp-item #11)) :kind 7 :sortText "00011" :filterText "float32" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float32")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face)) #("float64            Class" 0 1 (eglot--lsp-item (:label #("float64" 0 1 (eglot--lsp-item #12)) :kind 7 :sortText "00012" :filterText "float64" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float64")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face))) 0 nil 20)
  apply(#f(compiled-function (&rest args) #<bytecode 0x5c46c93f194842c>) ((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)) 0 24 (#("flag              \"flag\"" 0 1 (eglot--lsp-item (:label #("flag" 0 1 (eglot--lsp-item #10)) :kind 9 :detail "\"flag\"" :sortText "00001" :filterText "flag" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flag") :additionalTextEdits [(:range ... :newText "\"\n\11\"flag")]) face completions-common-part completion-score 0.75) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 18 24 (face font-lock-function-name-face)) #("flags     *pflag.FlagSet" 0 1 (eglot--lsp-item (:label #("flags" 0 1 (eglot--lsp-item #11)) :kind 6 :detail "*pflag.FlagSet" :preselect t :sortText "00000" :filterText "flags" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flags")) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 10 24 (face font-lock-function-name-face)) #("flate   \"compress/flate\"" 0 1 (eglot--lsp-item (:label #("flate" 0 1 (eglot--lsp-item #12)) :kind 9 :detail "\"compress/flate\"" :sortText "00002" :filterText "flate" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "flate") :additionalTextEdits [(:range ... :newText "\n\11\"compress/flate\"")]) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 8 24 (face font-lock-function-name-face)) #("float32            Class" 0 1 (eglot--lsp-item (:label #("float32" 0 1 (eglot--lsp-item #13)) :kind 7 :sortText "00011" :filterText "float32" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "float32")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face)) #("float64            Class" 0 1 (eglot--lsp-item (:label #("float64" 0 1 (eglot--lsp-item #14)) :kind 7 :sortText "00012" :filterText "float64" :insertTextFormat 2 :textEdit (:range (:start ... :end ...) :newText "float64")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face))) 0 nil 20))
  corfu--popup-show((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)) 0 24 (#("flag              \"flag\"" 0 1 (eglot--lsp-item (:label #("flag" 0 1 (eglot--lsp-item #8)) :kind 9 :detail "\"flag\"" :sortText "00001" :filterText "flag" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flag") :additionalTextEdits [(:range (:start ... :end ...) :newText "\"\n\11\"flag")]) face completions-common-part completion-score 0.75) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 18 24 (face font-lock-function-name-face)) #("flags     *pflag.FlagSet" 0 1 (eglot--lsp-item (:label #("flags" 0 1 (eglot--lsp-item #9)) :kind 6 :detail "*pflag.FlagSet" :preselect t :sortText "00000" :filterText "flags" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flags")) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 10 24 (face font-lock-function-name-face)) #("flate   \"compress/flate\"" 0 1 (eglot--lsp-item (:label #("flate" 0 1 (eglot--lsp-item #10)) :kind 9 :detail "\"compress/flate\"" :sortText "00002" :filterText "flate" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "flate") :additionalTextEdits [(:range (:start ... :end ...) :newText "\n\11\"compress/flate\"")]) face completions-common-part completion-score 0.6) 1 3 (face completions-common-part) 3 4 (face completions-first-difference) 8 24 (face font-lock-function-name-face)) #("float32            Class" 0 1 (eglot--lsp-item (:label #("float32" 0 1 (eglot--lsp-item #11)) :kind 7 :sortText "00011" :filterText "float32" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float32")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face)) #("float64            Class" 0 1 (eglot--lsp-item (:label #("float64" 0 1 (eglot--lsp-item #12)) :kind 7 :sortText "00012" :filterText "float64" :insertTextFormat 2 :textEdit (:range (:start (:line 37 :character 1) :end (:line 37 :character 4)) :newText "float64")) face completions-common-part completion-score 0.21428571428571427) 1 2 (face completions-common-part) 3 4 (face completions-common-part) 4 5 (face completions-first-difference) 19 24 (face font-lock-function-name-face))) 0 nil 20)
  corfu--candidates-popup((#<window 1 on scrape.go> 1280 (4 . 37) 0 nil 1280 (4 . 37) nil (0 . 0) (1 . 0)))
  #f(compiled-function (&optional auto) #<bytecode -0x17b87a67d3e85c3>)(auto)
  apply(#f(compiled-function (&optional auto) #<bytecode -0x17b87a67d3e85c3>) auto)
  #f(compiled-function (&rest args) #<bytecode -0xfd5ea2388186709>)(auto)
  apply(#f(compiled-function (&rest args) #<bytecode -0xfd5ea2388186709>) auto)
  corfu--exhibit(auto)
  corfu--auto-complete-deferred((#<window 1 on scrape.go> #<buffer scrape.go> 238 1283))
  apply(corfu--auto-complete-deferred (#<window 1 on scrape.go> #<buffer scrape.go> 238 1283))
  timer-event-handler([t 25749 32094 413976 nil corfu--auto-complete-deferred ((#<window 1 on scrape.go> #<buffer scrape.go> 238 1283)) nil 0 nil])

Here is the setup:

;; At the cursor completion engine.
(use-package corfu
  :straight (corfu :files (:defaults "extensions/*")
                   :includes (corfu-info))
  :custom
  (corfu-auto t) ; automatically trigger popups
  (corfu-popupinfo-delay 0)

  :bind
  (:map corfu-map ("RET" . nil)) ; use tab to complete

  :config
  (global-corfu-mode 1)
  (corfu-popupinfo-mode 1) ; add doc string next to corfu completion popup
  )

(use-package corfu-terminal :straight t
  :unless (display-graphic-p)
  :config
  (corfu-terminal-mode 1))

Gui version should be fine (but can't confirm this). Reverting back the commit fixed the issue. Thank you

minad commented 1 year ago

Yes, corfu-terminal must be adapted to handle posn popup position objects. For backward compatibility it should accept both integers and posn objects.

minad commented 1 year ago

The relevant commit is https://github.com/minad/corfu/commit/1fd386573472f20be53e9da91794b2ca9cf06279. cc @AkibAzmain

scturtle commented 1 year ago

https://codeberg.org/akib/emacs-corfu-terminal/pulls/23