[clang-tools-extra] [clangd] Do not offer extraction to variable for decl init expression (PR #69477)

Christian Kandeler via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 05:25:28 PST 2024


================
@@ -490,6 +491,13 @@ bool eligibleForExtraction(const SelectionTree::Node *N) {
         BO->getRHS() == OuterImplicit.ASTNode.get<Expr>())
       return false;
   }
+  if (const auto *Decl = Parent->ASTNode.get<VarDecl>()) {
+    if (!Decl->isInitCapture() &&
----------------
ckandeler wrote:

> For this case in particular, even if you said the refactoring is available for selection of `x = 1 + [[2 + 3]]` through 
> these heuristics, clangd will still end up extracting the full RHS, because that's the AST node we associated with that 
> selection.

I'm not sure I follow. In the example given above, invoking the tweak on the selection results in:
```
auto placeholder = 2 + 3;
int x = 1 + placeholder;
```
Which is exactly what I (the user) wanted. Am I misunderstanding something?

https://github.com/llvm/llvm-project/pull/69477


More information about the cfe-commits mailing list