Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libclang versus clang -cc1 #2

Open
phcerdan opened this issue Jan 23, 2017 · 4 comments
Open

libclang versus clang -cc1 #2

phcerdan opened this issue Jan 23, 2017 · 4 comments
Labels

Comments

@phcerdan
Copy link

Hi there, thanks for the plugin. I am trying to search a little bit about what is the difference between using libclang or using the clang front end clang -cc1? And only this FAQ.

I've found libclang unreliable with heavy templated code in c++, and happy to explore alternatives.

Any clarification, or link to information would be appreciated. Thanks!

@tweekmonster
Copy link
Owner

Hello! clang is a driver. It knows what to do to compile a program, including calling itself.

clang -cc1 is a frontend for specific features. To a user, it's useful for analyzing specific files, but you're limited to commands that are useful to the driver. You can see its flags with clang -cc1 --help | less

libclang is a library that can be used by programs to access its functions via FFI. A Python script could call the functions directly instead of requiring a Python implementation of Clang. This is useful if you want to analyze files in a way that's not possible using clang -cc1. For example, it's much easier to walk through a file's AST to find a specific function using libclang vs using clang -cc1 -ast-dump.

I've only gone ankle deep in C++, so I couldn't say how to improve completions for it. All I can tell you is that accurate completions boils down to parsing and presenting completions that are contextual for the current position in a file. But, that depends on how well clang understands the current source and the files it requires, which in turn depends on you. From my experience, bad/missing completions happen when generated headers are missing or not defining variables with -D.

If you're looking for another option, you could try the nvim-langserver-shim created by the venerable @tjdevries. There's a C++ langserver provided by Microsoft, but it looks like you'll need VS Code running.

@phcerdan
Copy link
Author

Thanks a lot for the explanation @tweekmonster. So, what is the advantage of using clang -cc1 in a completer, more flexibility?

I think my only problem with libclang is that I would like completion in headers with templates. And not really supported. neoinclude sounds that might help, but I haven't tried it yet.

@tweekmonster
Copy link
Owner

So, what is the advantage of using clang -cc1 in a completer, more flexibility?

For this plugin, it's simply faster for as-you-type completions. The completions provided by clang -cc1 were the same that were provided by deoplete-clang through libclang's Python bindings. I'm not sure why deoplete-clang was so slow, but I'm guessing there's a penalty for conversions to Python types, which is exaggerated by the sheer amount of completions.

It also helps that using clang -cc1 was much easier to implement.

I think my only problem with libclang is that I would like completion in headers with templates.

Maybe I could help if you post an examples, and explain what does and doesn't work.

neoinclude sounds that might help, but I haven't tried it yet.

This reminded me of a feature I wanted to add. 58079e5

@phcerdan
Copy link
Author

I will try to post a minimal example of what isn't working in headers next weekend. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants