syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.64k stars 4.89k forks source link

How to prevent from having company-clang backend set in variable company-backends when Clang support is enabled? #13150

Closed fperies closed 4 years ago

fperies commented 4 years ago

Description :octocat:

I do need to have Clang support enabled mainly for clang-format features. The issue I have is that auto-completion does not work because company-clang is hit first because it is in the first place of variable company-backends. Typically, the value of variable company-backends for a buffer in c++ mode is: (company-clang company-rtags company-c-headers (company-semantic company-dabbrev-code company-gtags company-etags company-keywords) company-files company-dabbrev)

I would prefer company jumps directly to company-rtags backend. How to achieve this behavior?

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart:

Auto-completion fails with nasty Clang errors like this for instance:

clang failed with error 1: /opt/llvm/x86_64/7.0.0.g631a/bin/clang -fsyntax-only -Xclang -code-completion-macros -x c++ -Xclang -code-completion-at=-:800:9 -

In file included from :1: ./Scheduler.hpp:3:10: fatal error: 'common/ut/mockUtils/Testable.hpp' file not found

include "common/ut/mockUtils/Testable.hpp"

     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

Expected behaviour: :heart: :smile:

Get a consistent auto-completion candidate from RTags

System Info :computer:

Backtrace :paw_prints:

N.A.
smile13241324 commented 4 years ago

@fperies I have double checked your issue and you should be able to achieve what you want by setting the layer like this:

     (c-c++ :variables
            c-c++-default-mode-for-headers 'c++-mode
            c-c++-backend 'rtags
            c-c++-enable-clang-format-on-save t)

This layer has been revised by sylable not long ago, please double check the documentation for other useful settings like enabling sorting of includes.

Please close this ticket when your issue is resolved.

fperies commented 4 years ago

@smile13241324 : Thank you for your answer !

Unfortunately it still does not work.

After having rebased on develop branch with recent commit ( 2d7480f67- 3days ago), and changed my Spacemacs layers as you said (rtags backend first then clang support)I still don't get completion proposals from Rtags. When I edit a C++ source file and display variable value of company-backends I get:

Value:
(company-c-headers
 (company-semantic company-dabbrev-code company-gtags company-etags company-keywords)
 company-files company-dabbrev)
Original value was 
(company-bbdb company-eclim company-semantic company-clang company-xcode company-cmake company-capf company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

I don't even see anymore company-rtags as part of company-backends !!

Do you have any clue that would explain this missing setting ??

Thank Regards

smile13241324 commented 4 years ago

I think rtags support is broken, I see that it is registered as company backend in the code but it seems to be overwriten somewhere again. I will try to have a more detailed look into this in the next few days.

fperies commented 4 years ago

@smile13241324 Do you have any update on this issue ?? According to Gitter Chat, it seems that this regression came from commit d536b36d154... Thanks !

smile13241324 commented 4 years ago

@fperies sorry, unfortunately not, somehow real life kept me busy. I will work on your issue next.

smile13241324 commented 4 years ago

So, looks like there is something wrong with the load order, company-rtags's post-init-company function is not properly called, no idea why right now.

When I call it manually I see company-rtags in the list of backends but it is not selected. Not sure if this needs to be set manually.

Looks like its time to read this finally up.

fperies commented 4 years ago

Hello @smile13241324 , Could you please precise the exact function name of what you call "company-rtags's post-init-company" ? I don't get what it is exactly...

Thanks

smile13241324 commented 4 years ago

Sure I am talking about c-c++/post-init-company function in package.el of the layer. This is loaded after company has been loaded but only if company is also declared in the package layer list.

However this was missing therefore company-rtags backend was never set as company backend. This should be fixed now, @fperies could you double check?

However it looks like we also have a problem with c++-mode-local-vars-hook. This is when I restart spacemacs and open an existing buffer which had c++-mode set the content of above hook is not run and subsequently non lsp backends are not properly set. @syl20bnr can you have a look here? I have no idea were this comes from, I have only noticed that when I use another hook it is just run as usual.

fperies commented 4 years ago

@smile13241324 I've just checked the expected behaviour and it now works very well !!

Thank you very much for your support !! :smile: