[clangd] Selection: Prune gtest TEST()s earlier
authorSam McCall <sam.mccall@gmail.com>
Mon, 10 Jan 2022 23:09:58 +0000 (00:09 +0100)
committerSam McCall <sam.mccall@gmail.com>
Thu, 13 Jan 2022 12:58:42 +0000 (13:58 +0100)
commit2b2dbe6126f8c016e0cbef45a6d22e1359ce39fd
treebf988fc5a13d35bbedf1b3ac49ec1a41d0f40deb
parenta9bf32763d3929672fe243f84e6a103c91260ef0
[clangd] Selection: Prune gtest TEST()s earlier

When searching for AST nodes that may overlap the selection, mayHit() was only
attempting to prune nodes whose begin/end are both in the main file.

While failing to prune never gives wrong results, it hurts performance.
In GTest unit-tests, `TEST()` macros at the top level declare classes.
These were never pruned and we traversed *every* such class for any selection.

We fix this by reasoning about what tokens such a node might claim.
They must lie within its ultimate macro expansion range, so if this doesn't
overlap with the selection, we can prune the node.

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