[clangd-dev] Prototyping a "type hierarchy" request

Sam McCall via clangd-dev clangd-dev at lists.llvm.org
Mon Aug 27 23:21:15 PDT 2018

On Mon, Aug 27, 2018, 22:22 Simon Marchi via clangd-dev <
clangd-dev at lists.llvm.org> wrote:

> Hi all,
> There is no request to obtain the type hierarchy starting from a
> particular type in the LSP specification yet, but there are some
> proposals [1] 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:
> https://reviews.llvm.org/D51311

Haven't looked at the patch yet, but this sounds awesome and you're right
about the index needing work to support this.
One approach would be to use the XRefs APIs that are landing, make
"overrides" a role, and allow the payload to be a symbol ID rather than a

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:
> https://github.com/Microsoft/vscode-languageserver-node/pull/346#issuecomment-416256239
> 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.
Dumb question, what are non-virtual overrides? I'm thinking CRTP, but I'm
probably overthinking this :-)

> Does anybody have any pointers on how I could do this?
> Simon
> [1] https://github.com/Microsoft/vscode-languageserver-node/pull/346
> _______________________________________________
> clangd-dev mailing list
> clangd-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20180828/78be1122/attachment.html>

More information about the clangd-dev mailing list