This is an archive of the discontinued LLVM Phabricator instance.

[clangd] [RFC] Use libclang and CXTranslationUnit instead of ASTUnit
AbandonedPublic

Authored by malaperle-ericsson on Mar 15 2017, 7:24 PM.

Details

Reviewers
None
Summary

This change uses the higher level libclang library to achieve similar
results as before. It paves the way to be able to use other things
from the library such as clang_codeCompleteAt. Using CXTranslationUnits
while keeping the current ASTUnit would mean parsing the files twice
so this is why this change removes the ASTUnits.

Event Timeline

malaperle-ericsson edited the summary of this revision. (Show Details)Mar 15 2017, 7:26 PM
malaperle-ericsson added a reviewer: bkramer.
malaperle-ericsson set the repository for this revision to rL LLVM.
malaperle-ericsson added a subscriber: cfe-commits.

Just to make things clear, I'm really not sure if this is the right approach and I'm looking for opinions before going further in that direction (code completion).

bkramer resigned from this revision.Mar 16 2017, 3:52 AM

It's not. the goal is to get rid of ASTUnit inside of clangd in the long term as it's a big problem for extensibility. libclang is just a wrapper for ASTUnit, with even more problems.

If you want to get completion running, just call ASTUnit::CodeComplete.

It's not. the goal is to get rid of ASTUnit inside of clangd in the long term as it's a big problem for extensibility. libclang is just a wrapper for ASTUnit, with even more problems.

If you want to get completion running, just call ASTUnit::CodeComplete.

Thanks a lot. When you say the goal is to get rid of ASTUnit, what would it be replaced with? Also, why would one use libclang over ASTUnit (libclangFrontend) then? Perhaps there's some documentation listing the pros and cons?

libclang is supposed to be used for bindings to other languages (it's a pure C interface) and its stable. ASTUnit is the C++ side of libclang, libclang is just a thin wrapper around ASTUnit. ASTUnit itself suffers from lots of technical debt because clang changed since ASTUnit was created and ASTUnit was never refactored to accommodate that.

Even in the current state using ASTUnit gives you more control over clang, e.g. it lets you use the VFS which is not exposed in libclang. At some point we're going to need a cleaner replacement for ASTUnit, but currently it's the only place in clang that supports the precompiled preamble needed for speedy code completion.

Perfect. Thanks a lot for the explanation!

Abandoned because of wrong approach.