[clangd] Selection handles CXXBaseSpecifier
authorNathan James <n.james93@hotmail.co.uk>
Tue, 26 Jan 2021 18:58:53 +0000 (18:58 +0000)
committerNathan James <n.james93@hotmail.co.uk>
Tue, 26 Jan 2021 18:58:53 +0000 (18:58 +0000)
Selection now includes the virtual and access modifier as part of their range for cxx base specifiers.

Reviewed By: sammccall

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

clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/lib/AST/ASTTypeTraits.cpp

index cec6c03..017f4b2 100644 (file)
@@ -493,6 +493,9 @@ public:
     return traverseNode(
         X, [&] { return Base::TraverseConstructorInitializer(X); });
   }
+  bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &X) {
+    return traverseNode(&X, [&] { return Base::TraverseCXXBaseSpecifier(X); });
+  }
   // Stmt is the same, but this form allows the data recursion optimization.
   bool dataTraverseStmtPre(Stmt *X) {
     if (!X || isImplicit(X))
index 6402f4e..4bc0379 100644 (file)
@@ -1024,6 +1024,12 @@ TEST(RenameTest, Renameable) {
         }
       )cpp",
        "new name is the same", !HeaderFile, nullptr, "SameName"},
+      {R"cpp(// Ensure it doesn't associate base specifier with base name.
+        struct A {};
+        struct B : priv^ate A {};
+      )cpp",
+       "Cannot rename symbol: there is no symbol at the given location", false,
+       nullptr},
   };
 
   for (const auto& Case : Cases) {
index efe0638..f187020 100644 (file)
@@ -261,6 +261,27 @@ TEST(SelectionTest, CommonAncestor) {
           )cpp",
           "StringLiteral", // Not DeclRefExpr to operator()!
       },
+      {
+          R"cpp(
+            struct Foo {};
+            struct Bar : [[v^ir^tual private Foo]] {};
+          )cpp",
+          "CXXBaseSpecifier",
+      },
+      {
+          R"cpp(
+            struct Foo {};
+            struct Bar : private [[Fo^o]] {};
+          )cpp",
+          "RecordTypeLoc",
+      },
+      {
+          R"cpp(
+            struct Foo {};
+            struct Bar : [[Fo^o]] {};
+          )cpp",
+          "RecordTypeLoc",
+      },
 
       // Point selections.
       {"void foo() { [[^foo]](); }", "DeclRefExpr"},
index b040f9e..8f9ceea 100644 (file)
@@ -193,5 +193,7 @@ SourceRange DynTypedNode::getSourceRange() const {
     return TAL->getSourceRange();
   if (const auto *C = get<OMPClause>())
     return SourceRange(C->getBeginLoc(), C->getEndLoc());
+  if (const auto *CBS = get<CXXBaseSpecifier>())
+    return CBS->getSourceRange();
   return SourceRange();
 }