abingham / emacs-ycmd

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

Emacs Lisp? #361

Closed Alexander-Shukaev closed 7 years ago

Alexander-Shukaev commented 7 years ago

Hi,

I see that

(defcustom ycmd-file-type-map
    ...
    (emacs-lisp-mode . ("elisp"))
    ...)

has been added. As a result, after upgrade I keep getting

Traceback (most recent call last):
  File "/usr/share/vim/vimfiles/third_party/ycmd/ycmd/../ycmd/server_state.py", line 94, in FiletypeCompletionAvailable
    self.GetFiletypeCompleter( filetypes )
  File "/usr/share/vim/vimfiles/third_party/ycmd/ycmd/../ycmd/server_state.py", line 89, in GetFiletypeCompleter
    current_filetypes ) )
ValueError: No semantic completer exists for filetypes: [u'elisp']

I'm not sure about the motivation behind this. Can I expect semantic completion for Emacs Lisp now or is it a mistake?

ptrv commented 7 years ago

The ycmd-file-type-map does not only contain file types with semantic completion. elisp has been added because the identifier completion engine of ycmd has now better support to find Emacs Lisp identifiers.

The error message is from trying to get semantic completion in a mode that does not support it.

Alexander-Shukaev commented 7 years ago

I mean, what should I do now? How to avoid the error and still use elisp?

ptrv commented 7 years ago

To get rid of the message do not perform semantic completion in elisp. Usually in elisp this is not happening except when forcing semantic completion. Do you have ycmd-force-sematic-completion set to t? This would explain the error message of course.

It would help if you could post your emacs-ycmd config.

Alexander-Shukaev commented 7 years ago

Nothing fancy:

 (setq-default
    ycmd-request-log-level     'verbose
    ycmd-request-message-level 'verbose
    ycmd-global-config "~/.ycm_extra_conf.py"
    ycmd-extra-conf-whitelist '("~/*")
    ycmd-server-command `("python2" ,(cond ((eq system-type 'windows-nt)
                                            "C:/Tools/x64/YCMD/ycmd/")
                                           (t
                                            "/usr/share/vim/vimfiles/third_party/ycmd/ycmd/"))))
(add-hook 'after-init-hook #'company-ycmd-setup)
(add-hook 'after-init-hook #'flycheck-ycmd-setup)

As you can see, I never touch ycmd-force-sematic-completion, that's why I'm confused.

vheon commented 7 years ago

Those kind of error are "normal". When you ask for completion ycmd checks if there is a semantic engine available for the file you're editing. The exception that is logged is actually catched and we fall back to identifier completer. So nothing to worry about.

ptrv commented 7 years ago

@vheon Thanks for clarifying.

Alexander-Shukaev commented 7 years ago

Fine, but it's hard to ignore another error from *Messages*

Error sending FileReadyToParse request: (error Selecting deleted buffer)

that comes from ycmd--event-notification on certain actions in emacs-lisp buffer. How do I deal with it?

ptrv commented 7 years ago

Can you provide reproduction steps for the error?

What do you mean by "certain actions"?

The error says that the current buffer from the time point when the request was started doesn't exist anymore at the time the actual request is sent.

Alexander-Shukaev commented 7 years ago

So, this problem I've fixed. It was because there was a temporary buffer with emacs-lisp-mode created on certain operations.

Now, the only issue that I have with (emacs-lisp-mode . ("elisp")) is ycmd-goto. In fact, let's say it's bound to g g when ycmd-mode is active and find-function-at-point is bound to g g when it's inactive, then with (emacs-lisp-mode . ("elisp")) I now get No semantic completer exists for filetypes: [u'elisp']. It means that even if the completion is better now for Emacs Lisp as you claim, the jumping functionality is not there at all. Would it be reasonable to fallback to find-function-at-point in ycmd-goto for emacs-lisp-mode at least for now?

ptrv commented 7 years ago

The improvements for Emacs Lisp in ycmd was just regarding identifier completion. There is still no semantic completion for Emacs Lisp which would provide the GoTo functionality.

I would recommend to just disable ycmd-mode for emacs-lisp-mode. It seems you are using global-ycmd-mode, you could set ycmd-global-modes variable: (setq ycmd-global-modes '(not emacs-lisp-mode)).

To add find-function-at-point as fallback into ycmd.el is in my opinion no a good idea. It's too emacs-lisp-mode specific. We already have a hook running on an exception: ycmd-after-exception-hook.

You could achieve your fallback suggestion by adding a function to that hook which does the fallback. Something like:

(defun my-ycmd-fallback (command buffer pos response)
  (when (string= (car command) "GoTo")
    (find-function-at-point)))
(add-hook 'ycmd-after-exception-hook #'my-ycmd-fallback")

I still suggest disabling ycmd-mode in emacs-lisp-mode. You will get these ycmd "error" messages for all modes that are in ycmd-file-type-map but don't have a semantic completer if you try to perform a functionality only available for semantic completers.

I had another look at the Error sending FileReadyToParse request: (error Selecting deleted buffer) message. I also encountered it today with ycmd-global-mode enabled. It can be reproduced with ycmd-global-mode enabled in a *Customize ...* buffer when trying to save the buffer. I'll have another look into this.