emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.76k stars 873 forks source link

cl--assertion-failed: Assertion failed: (functionp fetcher) #3838

Open JohnC32 opened 1 year ago

JohnC32 commented 1 year ago

Thank you for the bug report

Bug description

Using lsp-mode 2dd3340 from Nov-30-2022 (and latest ccls, etc.). I'm seeing on Emacs 27 when using code lens and I click on a ref:

 struct Name {  1 ref

Using M-x toggle-debug-on-error, I see:

 Debugger entered--Lisp error: (cl-assertion-failed ((functionp fetcher) nil))
   cl--assertion-failed((functionp fetcher))
   xref--show-xref-buffer((#<xref-item xref-item-157894582ce0>) ((window . #<window 12 on file123.cpp<test1234>>) (display-action)))
   xref--show-xrefs((#<xref-item xref-item-157894582ce0>) nil)
   #f(compiled-function (server command arguments) #<bytecode 0x15789418e60d>)(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
   apply(#f(compiled-function (server command arguments) #<bytecode 0x15789418e60d>) ccls (ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."]))
   #f(compiled-function (arg &rest args) #<bytecode 0x1578955fe1a5>)(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
   apply(#f(compiled-function (arg &rest args) #<bytecode 0x1578955fe1a5>) ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
   lsp-execute-command(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
   lsp--execute-command(#<hash-table equal 3/65 0x15789566aa85>)
   #f(compiled-function () (interactive nil) #<bytecode 0x157895164079>)()
   funcall-interactively(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>))
   call-interactively(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>) nil nil)
   command-execute(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>))

I'm wondering if this is related to https://github.com/emacs-lsp/lsp-mode/issues/898

Steps to reproduce

Emacs 27 with latest (as of Dec-3-2022) lsp-mode, lsp-ui, ccls. Index a C++ file using ccls, then mouse click on a "N refs" annotation.

Expected behavior

No assert

Which Language Server did you use?

ccls

OS

Linux

Error callstack

Debugger entered--Lisp error: (cl-assertion-failed ((functionp fetcher) nil))
  cl--assertion-failed((functionp fetcher))
  xref--show-xref-buffer((#<xref-item xref-item-157894582ce0>) ((window . #<window 12 on file123.cpp<test1234>>) (display-action)))
  xref--show-xrefs((#<xref-item xref-item-157894582ce0>) nil)
  #f(compiled-function (server command arguments) #<bytecode 0x15789418e60d>)(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
  apply(#f(compiled-function (server command arguments) #<bytecode 0x15789418e60d>) ccls (ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."]))
  #f(compiled-function (arg &rest args) #<bytecode 0x1578955fe1a5>)(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
  apply(#f(compiled-function (arg &rest args) #<bytecode 0x1578955fe1a5>) ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
  lsp-execute-command(ccls ccls\.xref ["{\"usr\":17743960827798335977,\"kind\":2,\"field\":\"uses..."])
  lsp--execute-command(#<hash-table equal 3/65 0x15789566aa85>)
  #f(compiled-function () (interactive nil) #<bytecode 0x157895164079>)()
  funcall-interactively(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>))
  call-interactively(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>) nil nil)
  command-execute(#f(compiled-function () (interactive nil) #<bytecode 0x157895164079>))

Anything else?

No response

yyoncho commented 1 year ago

Are you getting the same error if you do M-x lsp-find-references?

JohnC32 commented 1 year ago

Placing the point on a item (on struct Name in my example) works. Both M-x lsp-find-references and M-x xref-find-references work. It's only when I mouse click on the "N refs" annotation.

JohnC32 commented 1 year ago

Note, C-h k then mouse click on N refs annotation gives:

   <mouse-1> at that spot runs the command #[0 "\301\300!\207" [#s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8125 data ("title" "4 refs" "command" "ccls.xref" "arguments" ["{\"usr\":8398225106362275994,\"kind\":4,\"field\":\"uses\"}"])) lsp--execute-command] 2 nil nil]

Thus it doesn't seem to be running xref-find-references or lsp-find-references?

yyoncho commented 1 year ago

I saw it - it is bug in emacs-ccls.

JohnC32 commented 1 year ago

Could you try pointing me in the right direction with the general idea of what needs to be fixed. I can then try fixing it?

yyoncho commented 1 year ago

https://github.com/emacs-lsp/emacs-ccls/blob/master/ccls-code-lens.el#L73 this line should call lsp-show-xrefs It is one line fix.

JohnC32 commented 1 year ago

The fix, https://github.com/emacs-lsp/emacs-ccls/pull/115, address the assertion failed problem. However, I see a performance issue. Both emacs and ccls processes consume excessive CPU (~100%) for quite a while while the lenses are on when working in a rather large code base. Is this a known issue?