[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

David Goldman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 24 11:05:57 PST 2024


================
@@ -778,12 +868,44 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
     return makeError(ReasonToReject::NoSymbolFound);
   if (DeclsUnderCursor.size() > 1)
     return makeError(ReasonToReject::AmbiguousSymbol);
+  std::string Placeholder;
+  // We expect the token under the cursor to be changed unless the user is
+  // renaming an Objective-C selector with multiple pieces and only renames
+  // some of the selector piece(s).
+  bool RenamingCurToken = true;
   const auto &RenameDecl = **DeclsUnderCursor.begin();
-  const auto *ID = RenameDecl.getIdentifier();
-  if (!ID)
-    return makeError(ReasonToReject::UnsupportedSymbol);
-  if (ID->getName() == RInputs.NewName)
-    return makeError(ReasonToReject::SameName);
+  if (const auto *MD = dyn_cast<ObjCMethodDecl>(&RenameDecl)) {
+    const auto Sel = MD->getSelector();
+    if (Sel.getAsString() == RInputs.NewName)
+      return makeError(ReasonToReject::SameName);
+    if (Sel.getNumArgs() != RInputs.NewName.count(':') &&
+        RInputs.NewName != "__clangd_rename_placeholder")
+      return makeError(
+          InvalidName{InvalidName::BadIdentifier, RInputs.NewName.str()});
----------------
DavidGoldman wrote:

Done

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


More information about the cfe-commits mailing list