[clang-tools-extra] bc49819 - [clangd] Allow renaming class templates in cross-file rename.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 21 00:59:23 PST 2020


Author: Haojian Wu
Date: 2020-02-21T09:57:10+01:00
New Revision: bc498198b5559829d8f7138db01b0f51afefe2a7

URL: https://github.com/llvm/llvm-project/commit/bc498198b5559829d8f7138db01b0f51afefe2a7
DIFF: https://github.com/llvm/llvm-project/commit/bc498198b5559829d8f7138db01b0f51afefe2a7.diff

LOG: [clangd] Allow renaming class templates in cross-file rename.

Summary:
It was disabled because we don't handle explicit template
specialization well (due to the index limitation).

renaming templates is normal in practic, rather than disabling it, this patch
allows to rename them though it is not perfect (just a known limitation).

Context: https://github.com/clangd/clangd/issues/280

Reviewers: kbobyrev

Reviewed By: kbobyrev

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74709

Added: 
    

Modified: 
    clang-tools-extra/clangd/refactor/Rename.cpp
    clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index c5dd09b99508..02e355ecf164 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -184,13 +184,6 @@ llvm::Optional<ReasonToReject> renameable(const NamedDecl &RenameDecl,
   if (!Index)
     return ReasonToReject::NoIndexProvided;
 
-  // Blacklist symbols that are not supported yet in cross-file mode due to the
-  // limitations of our index.
-  // FIXME: Renaming templates requires to rename all related specializations,
-  // our index doesn't have this information.
-  if (RenameDecl.getDescribedTemplate())
-    return ReasonToReject::UnsupportedSymbol;
-
   // FIXME: Renaming virtual methods requires to rename all overridens in
   // subclasses, our index doesn't have this information.
   // Note: Within-file rename does support this through the AST.

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 3561ff6438f7..aa08be484ea3 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -887,6 +887,23 @@ TEST(CrossFileRenameTests, WithUpToDateIndex) {
         }
       )cpp",
       },
+      {
+          // class templates.
+          R"cpp(
+        template <typename T>
+        class [[Foo]] {};
+        // FIXME: explicit template specilizations are not supported due the
+        // clangd index limitations.
+        template <>
+        class Foo<double> {};
+      )cpp",
+          R"cpp(
+        #include "foo.h"
+        void func() {
+          [[F^oo]]<int> foo;
+        }
+      )cpp",
+      },
       {
           // class methods.
           R"cpp(


        


More information about the cfe-commits mailing list