emacs-ycmd icon indicating copy to clipboard operation
emacs-ycmd copied to clipboard

How do I test that company integration is working?

Open jlargentaye opened this issue 10 years ago • 4 comments

I got emacs-ycmd to work on a project (took a bit of work...), as verified by enabling ycmd-mode on a file and using M-x ycmd-display-completions.

I've run company-ymcd-setup (which I see only needs to be run once, as all it does is set company-ycmd at the front of company's completer list).

However, if I enable company-mode in a file of my project, I can't reliably get completions:

  • nothing comes up if I start typing a function prefix (up to a completion trigger such as underscore), and wait
  • if I then try to run M-x company-ycmd, it returns "no completion at point".

I did manage to get company-mode to display results for this file once, but I can't reproduce it. I don't know which backend provided the candidates, but they were identical to what ycmd-display-completions returned so I assume it was company-ycmd.

I tried all combinations of enabling/disabling company-mode and ycmd-mode in the buffer.

In the ycmd-server buffer, I only see "INFO - Adding buffer identifiers for file:" when enabling ycmd-mode. I would expect that to come up with company-mode as well, but that doesn't seem to be the case.

jlargentaye avatar Sep 16 '15 17:09 jlargentaye

Hi @jlargentaye

Sorry to hear that you have problems with configuing emacs-ycmd. Did you configure emacs-ycmd like described in the Quickstart section of the README? Could you maybe post your configuration? Also, do you have a project specific .ycm_extra_conf.py in your project?

If you start typing you get the identifier based completion first. This will give you keywords from the file. After you inserted a completion trigger, for c++ for example these are ., -> or :: you get semantic completion. An underscore is not a completion trigger for semantic completion.

ptrv avatar Sep 19 '15 18:09 ptrv

Hi @ptrv,

thanks for your considerate response :)

It did end up working, but I couldn't find feedback in Messages or ycmd-server with progress/state information to explain why it wasn't working before and started working now. Note that I'm doing this on a C project.

To answer your questions, I did configure emacs-ycmd appropriately following the Quickstart, modulo the following:

  • installed emacs-ycmd from MELPA via integrated package.el
  • relied on autoloads and manually start ycmd-mode for buffers I wanted. I didn't do a (require ycmd). I didn't set global-ycmd-mode nor added it to c++-mode-hook.
  • didn't set ycmd-global-config, as I didn't need it. I have a .ycm_extra_conf.py for my project.
  • I did set ycmd-extra-conf-whitelist after I was having problems getting it to accept my project's .ycm_extra_conf.py. Turned out I had a syntax error in it.

I did do a require of company-ycmd and ran company-ycmd-setup, and subsequently did a Customize of Company Backends to add company-ycmd for all sessions.

Ultimately, my confusion comes down to a couple points:

  • do I need to enable ycmd-mode for company-ycmd to work? I was hoping not and dependency would be implicitly managed, and reading through company-ycmd.el (and my limited understanding of elisp) I figured company-ycmd didn't depend on ycmd-mode being enabled. However experimentation seems to show it does need it.
  • I'd like there to be more feedback (maybe with a debug enabled?) about what company-ycmd and ycmd-mode are doing. Why is a completion failing? Is it because the YCMd server returning no results? Some other problem?

Anyhow, thanks a lot this wonderful package :)

jlargentaye avatar Sep 20 '15 00:09 jlargentaye

Hi @jlargentaye

I am happy that ycmd-mode and company-ycmd is working for you now.

do I need to enable ycmd-mode for company-ycmd to work?

Yes. There is one check in company-ycmd in the function company-ycmd--prefix whether ycmd-mode is enabled or not. This function is a callback for company-mode to check if we can complete at the current point. When ycmd-mode is not enabled then the function returns nil and company-mode won't give any completions.

I was hoping not and dependency would be implicitly managed

Well, the problem is that you need to configure ycmd-mode before you can use it, e.g. hook into modes like c++-mode. How should company-ycmd know where to enable ycmd-mode if not specified.

The other reason for decoupling is that ycmd-mode can be used also with other completion packages like auto-complete, however ycmd-mode support for auto-complete is very limited compared to company-mode.

I'd like there to be more feedback (maybe with a debug enabled?) about what company-ycmd and ycmd-mode are doing. Why is a completion failing? Is it because the YCMd server returning no results? Some other problem?

You can set the variable ycmd--log-enabled to t, then you have another buffer called *ycmd-content-log* which shows you the client server communication. This should only be used for debugging and shouldn't be turned on by default.

ptrv avatar Sep 20 '15 11:09 ptrv

Alright, thanks for your responses! That answers my questions.

FWIW, from a usability perspective it would be best if company-ycmd could handle starting ycmd-mode as necessary, but I understand if there's no clear way to do so cleanly in the company framework. Alternatively update the README to make that unambiguous :)

Thanks again!

jlargentaye avatar Sep 21 '15 17:09 jlargentaye