[clangd-dev] Prototyping a "type hierarchy" request
Simon Marchi via clangd-dev
clangd-dev at lists.llvm.org
Mon Aug 27 10:10:10 PDT 2018
There is no request to obtain the type hierarchy starting from a
particular type in the LSP specification yet, but there are some
proposals  and some other language servers have their own extension
to the protocol to support that. I thought I would start prototyping
the feature in clangd to see how we can retrieve this information, so
that once the specification is modified to include such a request, we
are not too far from supporting it. It can also help steer the proposed
changes to the specification to make sure it supports what we need for
the C++ language.
The scope of my prototype is: given a type or variable, recursively find
the base classes of that type (or the type of that variable). I am not
considering derived classes right now, because it would require dealing
with the index. Here is my work so far:
One extra feature I would really like to have is to be able to use the
"type hierarchy" request on a method (definition, declaration or call).
The result would tell you which nodes of the type hierarchy have an
implementation of this method (possibly with some more details, is it
virtual, is it pure, etc). It would allow implementing UIs such as the
one in this screenshot, which I find very useful:
I'm a bit stuck at this point: given a CXXMethodDecl representing the
method the user targeted, how can I tell if some base class (a
CXXRecordDecl) has a method matching this one. I saw
CXXMethodDecl::overridden_methods, but it only concerns virtual methods,
whereas for type hierarchy we would also want non-virtual overrides.
Does anybody have any pointers on how I could do this?
More information about the clangd-dev