[clangd] Handle declarators more consistently in Selection.
authorSam McCall <sam.mccall@gmail.com>
Tue, 4 Jan 2022 21:46:25 +0000 (22:46 +0100)
committerSam McCall <sam.mccall@gmail.com>
Wed, 5 Jan 2022 14:40:47 +0000 (15:40 +0100)
commit96f5cc1ee417f863f85756d1e56b1bed1bd76a7e
tree5b5adda20580589a3739e65b347fd36c58e57d93
parentbb2f87af0ac9ad8cc0efcb523e108e715ee9ab93
[clangd] Handle declarators more consistently in Selection.

Because declarators nest inside-out, we logically need to claim tokens for
parent declarators logically before child ones.
This is the ultimate reason we had problems with DeclaratorDecl, ArrayType etc.

However actually changing the order of traversal is hard, especially for nodes
that have both declarator and non-declarator children.
Since there's only a few TypeLocs corresponding to declarators, we just
have them claim the exact tokens rather than rely on nesting.

This fixes handling of complex declarators, like
`int (*Fun(OuterT^ype))(InnerType);`.

This avoids the need for the DeclaratorDecl early-claim hack, which is
removed.
Unfortunately the DeclaratorDecl early-claims were covering up an AST
anomaly around CXXConstructExpr, so we need to fix that up too.

Based on D116623 and D116618

Differential Revision: https://reviews.llvm.org/D116630
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp