[clangd][c++20]Consider rewritten binary operators in TargetFinder
authorJens Massberg <massberg@google.com>
Tue, 20 Jun 2023 11:25:56 +0000 (13:25 +0200)
committerJens Massberg <massberg@google.com>
Mon, 26 Jun 2023 09:26:10 +0000 (11:26 +0200)
commit6f065bfd633d7ca006f62b894108d5369dc46836
treed08a28d4b856b7b9fbde27f8b98300e3df85bc3e
parent8de9f2b558a046da15cf73191da627bdd83676ca
[clangd][c++20]Consider rewritten binary operators in TargetFinder

In C++20 some binary operations can be rewritten, e.g. `a != b`
can be rewritten to `!(a == b)` if `!=` is not explicitly defined.
The `TargetFinder` hasn't considered the corresponding `CXXRewrittenBinaryOperator` yet. This resulted that the definition of such operators couldn't be found
when navigating to such a `!=` operator, see https://github.com/clangd/clangd/issues/1476.

In this patch we add support of `CXXRewrittenBinaryOperator` in `FindTarget`.
In such a case we redirect to the inner binary operator of the decomposed form.
E.g. in case that `a != b` has been rewritten to `!(a == b)` we go to the
`==` operator. The `==` operator might be implicitly defined (e.g. by a `<=>`
operator), but this case is already handled, see the new test.

I'm not sure if I the hover test which is added in this patch is the right one,
but at least is passed with this patch and fails without it :)

Note, that it might be a bit missleading that hovering over a `!=` refers to
"instance method operator==".

Differential Revision: https://reviews.llvm.org/D153331
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp