adamcz created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman.
Herald added a project: clang.
adamcz requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92186

Files:
  clang-tools-extra/clangd/refactor/tweaks/AddUsing.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
@@ -2884,6 +2884,17 @@
 void fun() {
   yy();
 }
+)cpp"},
+            // Existing using with non-namespace part.
+            {R"cpp(
+#include "test.hpp"
+using one::two::ee::ee_one;
+one::t^wo::cc c;
+)cpp",
+             R"cpp(
+#include "test.hpp"
+using one::two::cc;using one::two::ee::ee_one;
+cc c;
 )cpp"}};
   llvm::StringMap<std::string> EditedFiles;
   for (const auto &Case : Cases) {
@@ -2892,7 +2903,7 @@
 namespace one {
 void oo() {}
 namespace two {
-enum ee {};
+enum ee {ee_one};
 void ff() {}
 class cc {
 public:
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -152,12 +152,14 @@
     if (SM.isBeforeInTranslationUnit(Inputs.Cursor, U->getUsingLoc()))
       // "Usings" is sorted, so we're done.
       break;
-    if (U->getQualifier()->getAsNamespace()->getCanonicalDecl() ==
-            QualifierToRemove.getNestedNameSpecifier()
-                ->getAsNamespace()
-                ->getCanonicalDecl() &&
-        U->getName() == Name) {
-      return InsertionPointData();
+    if (const auto *Namespace = U->getQualifier()->getAsNamespace()) {
+      if (Namespace->getCanonicalDecl() ==
+              QualifierToRemove.getNestedNameSpecifier()
+                  ->getAsNamespace()
+                  ->getCanonicalDecl() &&
+          U->getName() == Name) {
+        return InsertionPointData();
+      }
     }
 
     // Insertion point will be before last UsingDecl that affects cursor


Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2884,6 +2884,17 @@
 void fun() {
   yy();
 }
+)cpp"},
+            // Existing using with non-namespace part.
+            {R"cpp(
+#include "test.hpp"
+using one::two::ee::ee_one;
+one::t^wo::cc c;
+)cpp",
+             R"cpp(
+#include "test.hpp"
+using one::two::cc;using one::two::ee::ee_one;
+cc c;
 )cpp"}};
   llvm::StringMap<std::string> EditedFiles;
   for (const auto &Case : Cases) {
@@ -2892,7 +2903,7 @@
 namespace one {
 void oo() {}
 namespace two {
-enum ee {};
+enum ee {ee_one};
 void ff() {}
 class cc {
 public:
Index: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -152,12 +152,14 @@
     if (SM.isBeforeInTranslationUnit(Inputs.Cursor, U->getUsingLoc()))
       // "Usings" is sorted, so we're done.
       break;
-    if (U->getQualifier()->getAsNamespace()->getCanonicalDecl() ==
-            QualifierToRemove.getNestedNameSpecifier()
-                ->getAsNamespace()
-                ->getCanonicalDecl() &&
-        U->getName() == Name) {
-      return InsertionPointData();
+    if (const auto *Namespace = U->getQualifier()->getAsNamespace()) {
+      if (Namespace->getCanonicalDecl() ==
+              QualifierToRemove.getNestedNameSpecifier()
+                  ->getAsNamespace()
+                  ->getCanonicalDecl() &&
+          U->getName() == Name) {
+        return InsertionPointData();
+      }
     }
 
     // Insertion point will be before last UsingDecl that affects cursor
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to