abingham / emacs-ycmd

Emacs client for ycmd, the code completion system.
MIT License
384 stars 46 forks source link

eldoc error: (void-function nil) #409

Closed randomphrase closed 7 years ago

randomphrase commented 7 years ago

Hi,

I'm getting this error in the modeline with ycmd-eldoc enabled. Invoking (funcall eldoc-documentation-function) manually produces the following error:

Debugger entered--Lisp error: (void-function nil)
  nil()
  apply(nil nil)
  #[128 "\301\302\300!\"\207" [eldoc-documentation-function apply default-value] 4 "\n\n(fn &rest ARGS)"]()
  apply(#[128 "\301\302\300!\"\207" [eldoc-documentation-function apply default-value] 4 "\n\n(fn &rest ARGS)"] nil)
  #[128 "\300\301\"\206\300\302\"\207" [apply ycmd-eldoc--documentation-function #[128 "\301\302\300!\"\207" [eldoc-documentation-function apply default-value] 4 "\n\n(fn &rest ARGS)"] nil] 4 nil]()
  funcall(#[128 "\300\301\"\206\300\302\"\207" [apply ycmd-eldoc--documentation-function #[128 "\301\302\300!\"\207" [eldoc-documentation-function apply default-value] 4 "\n\n(fn &rest ARGS)"] nil] 4 nil])
  eval((funcall eldoc-documentation-function) nil)
  eval-expression((funcall eldoc-documentation-function) nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

I'm using spacemacs 0.200.8 with the ycmd layer enabled. ycmd completion and other functions seem to work just fine. This problem started occurring with the 0.200.8 release of spacemacs where ycmd-eldoc was enabled with ycmd.

I have a theory as to what could be happening. Specifically, in the the ycmd-eldoc-setup function we seem to be using add-function to wrap an existing value of eldoc-documentation-function in the event that it is already used. However this wrapping depends on the result of eval-when-compile, not on whether eldoc-documentation-function is actually bound. This means that when the function is compiled, it will always wrap - even when eldoc-documentation-function is nil. This produces the error above.

To test this theory I added (setq-default eldoc-documentation-function #'(lambda ())) to my init file. This seems to fix the problem - least it no longer drops into the debugger.

Let me know if I can provide any more information. Thanks in advance for your help.

abingham commented 7 years ago

@ptrv I think this is your baby. Any idea what's going on? @randomphrase's analysis seems pretty sound at first glance.

ptrv commented 7 years ago

I had a quick look, but I can not reproduce the issue.

@abingham You are using spacemacs, right? Can you reproduce this?

@randomphrase Can you provide more information? In which mode is this issue happening? Which emac version?

randomphrase commented 7 years ago

@ptrv I notice this in c++-mode. I don't know if this occurs in other modes, because this is the only one I use ycmd for. I see this problem on my two main workstations, both running emacs 24.5.1, one on Debian Testing (with the standard ycmd package) and one on Fedora 22 (with ycmd built from source).

If it helps any, my spacemacs init file is here.

ptrv commented 7 years ago

What is the default/globale value of eldoc-documentation-function in your Emacs version? It should be set toignore by default. Does spacemacs set it to nil at some point? The way we set it in ycmd-eldoc is the default way from the documentation:

Major modes should modify this variable using ‘add-function’, for example: (add-function :before-until (local 'eldoc-documentation-function)

'foo-mode-eldoc-function)

so that the global documentation function (i.e. the default value of the variable) is taken into account if the major mode specific function does not return any documentation.

Do you have an outdated byte compiled version of ycmd-eldoc lying around maybe which messes up your config?

randomphrase commented 7 years ago

OK, so here's the current value:

 eldoc-documentation-function is a variable defined in `eldoc.el'.
 Its value is #[128 "\300\301^B\"\206^K^@\300\302^B\"\207"
       [apply ycmd-eldoc--documentation-function
              #[128 "\301\302\300!^B\"\207"
                    [eldoc-documentation-function apply default-value]
                    4 "\n\n(fn &rest ARGS)"]
              nil]
       4 nil]

 Local in buffer pearson.cpp; global value is nil

So yes, the global value is nil. From grepping my .emacs.d directory (which includes spacemacs and installed packages) I could see some assignments to eldoc-documentation-function - but they were always buffer local values.

I'm not sure why you say the default value is ignore though? I'm looking in the eldoc.el.gz source file and I see it defined thus:

(defvar eldoc-documentation-function nil

Also to answer your question: I nuked my .emacs.d/elpa directory and forced a clean recompile of all packages just now.

Thanks for the help, hopefully we can get to the bottom of this.

randomphrase commented 7 years ago

OK this is an emacs version issue. I upgraded to emacs 25 and confirmed that the issue is fixed.

ptrv commented 7 years ago

This is strange. I think I used Emacs 24.5 with ycmd-eldoc without problems. But since we are supporting older Emacsen, maybe we should gueard against this error.

ptrv commented 7 years ago

@randomphrase Anyway, I am glad your issue is resolved. And thanks for the report.

randomphrase commented 7 years ago

NP. I'm not sure what the etiquette is here, but given that it's fixed for me, I'll close this issue.

ptrv commented 7 years ago

The default of eldoc-documentation-function has been changed in Emacs 25. I tried to reproduce this issue by setting the the value to nil, but I still don't get an error. Anyway, I changed now the code to not use add-function in #410