[clangd] Reduce availability of extract function
authorKadir Cetinkaya <kadircet@google.com>
Wed, 5 Aug 2020 20:18:39 +0000 (22:18 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Fri, 9 Oct 2020 08:12:48 +0000 (10:12 +0200)
commit2ff44935a5f56f755a4f47ad00ee0dec48e19832
tree7f7f950ea12bb27dfcd33ad27e519f86164c3e2b
parentefd8c9ed726df5376ca8ac3ddc75ab91a40dd873
[clangd] Reduce availability of extract function

This patch introduces hoisting detection logic into prepare state with
a partial AST traversal of the enclosing function.

We had some complaints from the users about this code action being almost always
available but failing most of the time. Hopefully this should reduce that noise.

The latency/correctness tradeoff is a bunch of hand-waving, but at least today
we don't have any other actions that are available on selection of statements,
so when we get to do the traversal it is quite likely that all the other checks
will bail out early. But this is still up for discussion, I am happy to abandon
the patch if you believe this is not practical.

Differential Revision: https://reviews.llvm.org/D85354
clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp