[PATCH] D67651: [clangd] No ExtractFunction on empty selections.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 17 03:20:18 PDT 2019


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67651

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -540,6 +540,8 @@
   EXPECT_EQ(apply("int x = 0; [[x++;]]"), "unavailable");
   // We don't support extraction from lambdas.
   EXPECT_EQ(apply("auto lam = [](){ [[int x;]] }; "), "unavailable");
+  // no selection.
+  EXPECT_EQ(apply("int ^x;"), "unavailable");
 
   // Ensure that end of Zone and Beginning of PostZone being adjacent doesn't
   // lead to break being included in the extraction zone.
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -623,6 +623,9 @@
 }
 
 bool ExtractFunction::prepare(const Selection &Inputs) {
+  // Don't trigger the tweak on an empty selection.
+  if (Inputs.SelectionBegin == Inputs.SelectionEnd)
+    return false;
   const Node *CommonAnc = Inputs.ASTSelection.commonAncestor();
   const SourceManager &SM = Inputs.AST.getSourceManager();
   const LangOptions &LangOpts = Inputs.AST.getASTContext().getLangOpts();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67651.220464.patch
Type: text/x-patch
Size: 1312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190917/d168b3f0/attachment.bin>


More information about the cfe-commits mailing list