radian-software / prescient.el

☄️ Simple but effective sorting and filtering for Emacs.
MIT License
603 stars 25 forks source link

Error in post-command-hook (corfu--post-command): (wrong-type-argument number-or-marker-p nil) #161

Closed aaronjensen closed 1 month ago

aaronjensen commented 2 months ago
Error in post-command-hook (corfu--post-command): (wrong-type-argument number-or-marker-p nil)

I see this error in some cases only with corfu-prescient

https://github.com/aaronjensen/corfu-repro

Open test.js, put the point after return and hit tab

okamsn commented 1 month ago

Hello, I'm having a bit of trouble installing LSP Mode right now. Is this something you also see when using Eglot, or is it only with LSP mode? Have you seen this with other CAPFs and/or combinations of CAPFs, or is it just these two in particular?

Also, are you able to produce a backtrace for this error?

aaronjensen commented 1 month ago

This is the only CAPF combination I've seen it with. I have other combinations and I haven't seen it. The CAPFs individually do not seem to cause it.

I haven't tried using eglot, I don't have a setup for it.

This is the backtrace:

Debugger entered--Lisp error: (wrong-type-argument hash-table-p nil)
  lsp-completion--annotate("return")
  apply(lsp-completion--annotate "return" nil)
  #f(compiled-function (cand &rest args) #<bytecode -0xec74f2af3c69c1b>)(#("return" 0 6 (face (prescient-primary-highlight) cape-capf-super ("return"))))
  corfu--affixate((#("return" 0 6 (face (prescient-primary-highlight) match-data (0 6 0 1 1 2 2 3 3 4 4 5 5 6) lsp-completion-prefix "return" lsp-completion-markers (31 #<marker (moves after insertion) at 37 in test.js>) lsp-completion-start-point 31 lsp-sort-text "15" lsp-completion-item #<hash-table equal 5/24 0x56335645 ...> :prescient-query "return" :prescient-ignore-case t :prescient-all-regexps ("\\(?:r[̧̣̱́̇̌̏̑]\\|[rŕŗřȑȓʳᵣṙṛṝṟⓡr𝐫𝑟𝒓𝓇𝓻𝔯𝕣𝖗𝗋𝗿𝘳𝙧𝚛]\\)\\(?:e[̀-̄̆-̧̨̣̭̰̉̌̏̑]\\|[eè-ëēĕėęěȅȇȩᵉḕḗḙḛḝẹẻẽếềểễệₑℯⅇⓔe𝐞𝑒𝒆𝓮𝔢𝕖𝖊𝖾𝗲𝘦𝙚𝚎]\\)\\(?:t[̧̣̦̭̱̇̈̌]\\|[tţťțᵗṫṭṯṱẗₜⓣt𝐭𝑡𝒕𝓉𝓽𝔱𝕥𝖙𝗍𝘁𝘵𝙩𝚝]\\)\\(?:u[̀-̄̆̈-̨̛̣̤̭̰̌̏̑]\\|[uù-üũūŭůűųưǔǖǘǚǜȕȗᵘᵤṳṵṷṹṻụủứừửữựⓤu𝐮𝑢𝒖𝓊𝓾𝔲𝕦𝖚𝗎𝘂𝘶𝙪𝚞]\\)\\(?:r[̧̣̱́̇̌̏̑]\\|[rŕŗřȑȓʳᵣṙṛṝṟⓡr𝐫𝑟𝒓𝓇𝓻𝔯𝕣𝖗𝗋𝗿𝘳𝙧𝚛]\\)\\(?:n[̧̣̭̱̀́̃̇̌]\\|[nñńņňǹṅṇṉṋⁿₙⓝn𝐧𝑛𝒏𝓃𝓷𝔫𝕟𝖓𝗇𝗻𝘯𝙣𝚗]\\)" "return" "\\br\\w*\\W*\\be\\w*\\W*\\bt\\w*\\W*\\bu\\w*\\W*\\br\\w*\\W*\\bn\\w*") :prescient-match-regexps ("\\(?:r[̧̣̱́̇̌̏̑]\\|[rŕŗřȑȓʳᵣṙṛṝṟⓡr𝐫𝑟𝒓𝓇𝓻𝔯𝕣𝖗𝗋𝗿𝘳𝙧𝚛]\\)\\(?:e[̀-̄̆-̧̨̣̭̰̉̌̏̑]\\|[eè-ëēĕėęěȅȇȩᵉḕḗḙḛḝẹẻẽếềểễệₑℯⅇⓔe𝐞𝑒𝒆𝓮𝔢𝕖𝖊𝖾𝗲𝘦𝙚𝚎]\\)\\(?:t[̧̣̦̭̱̇̈̌]\\|[tţťțᵗṫṭṯṱẗₜⓣt𝐭𝑡𝒕𝓉𝓽𝔱𝕥𝖙𝗍𝘁𝘵𝙩𝚝]\\)\\(?:u[̀-̄̆̈-̨̛̣̤̭̰̌̏̑]\\|[uù-üũūŭůűųưǔǖǘǚǜȕȗᵘᵤṳṵṷṹṻụủứừửữựⓤu𝐮𝑢𝒖𝓊𝓾𝔲𝕦𝖚𝗎𝘂𝘶𝙪𝚞]\\)\\(?:r[̧̣̱́̇̌̏̑]\\|[rŕŗřȑȓʳᵣṙṛṝṟⓡr𝐫𝑟𝒓𝓇𝓻𝔯𝕣𝖗𝗋𝗿𝘳𝙧𝚛]\\)\\(?:n[̧̣̭̱̀́̃̇̌]\\|[nñńņňǹṅṇṉṋⁿₙⓝn𝐧𝑛𝒏𝓃𝓷𝔫𝕟𝖓𝗇𝗻𝘯𝙣𝚗]\\)\\|return\\|\\br\\w*\\W*\\be\\w*\\W*\\bt\\w*\\W*\\bu\\w*\\W*\\br\\w*\\W*\\bn\\w*"))) #("return" 0 6 (face (prescient-primary-highlight) cape-capf-super ("return")))))
  corfu--candidates-popup((#<window 3 on test.js> 31 (28 . 14) 0 nil 31 (4 . 1) nil (0 . 0) (7 . 14)))
  corfu--exhibit()
  #<subr corfu--post-command>()
  ad-Advice-corfu--post-command(#<subr corfu--post-command>)
  apply(ad-Advice-corfu--post-command #<subr corfu--post-command> nil)
  corfu--post-command()

I updated the repo with enabling the debugger (which apparently is not very straightforward for post-command hooks).

The function raising the error is:

(defun lsp-completion--annotate (item)
  "Annotate ITEM detail."
  (-let (((&CompletionItem :detail? :kind? :label-details?) (plist-get (text-properties-at 0 item)
                                                       'lsp-completion-item)))
    (concat (when (and lsp-completion-show-detail detail?)
              (concat " " (s-replace "\r" "" detail?)))
            (when (and lsp-completion-show-label-description label-details?)
              (when-let ((description (and label-details? (lsp:label-details-description label-details?))))
                (format " %s" description)))
            (when lsp-completion-show-kind
              (when-let ((kind-name (and kind? (aref lsp-completion--item-kind kind?))))
                (format " (%s)" kind-name))))))

I also figured out how to reproduce the error without prescient at all, so this is not a prescient issue. Of note is that the reason I thought I could only reproduce the behavior with prescient is because prescient subtly changes the behavior when you hit tab at the end of return. Without prescient, "Sole match" is printed to the echo area. With it, a popup is shown showing return twice, both annotated with lsp-completion--annotate. I had to hack lsp-completion--annotate to work around the issue.

I'll close this out, but if the difference in behavior I mention is interesting at all, the repo reproduces that as well, just add this after lsp is required:

(defun lsp-completion--annotate (item)
  "Annotate ITEM detail."
  "ANNOTATE"
  )