[PATCH] D74112: [clangd] Filter out implicit references while renaming

Kirill Bobyrev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 6 02:35:12 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG10540e480dfb: [clangd] Filter out implicit references while renaming (authored by kbobyrev).

Changed prior to commit:
  https://reviews.llvm.org/D74112?vs=242822&id=242844#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74112/new/

https://reviews.llvm.org/D74112

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


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -33,7 +33,7 @@
 // Convert a Range to a Ref.
 Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
   Ref Result;
-  Result.Kind = RefKind::Reference;
+  Result.Kind = RefKind::Reference | RefKind::Spelled;
   Result.Location.Start.setLine(Range.start.line);
   Result.Location.Start.setColumn(Range.start.character);
   Result.Location.End.setLine(Range.end.line);
@@ -440,6 +440,23 @@
         template <template<typename> class Z> struct Bar { };
         template <> struct Bar<[[Foo]]> {};
       )cpp",
+
+      {
+          // Implicit references in macro expansions.
+          R"cpp(
+        class [[Fo^o]] {};
+        #define FooFoo Foo
+        #define FOO Foo
+      )cpp",
+          R"cpp(
+        #include "foo.h"
+        void bar() {
+          [[Foo]] x;
+          FOO y;
+          FooFoo z;
+        }
+      )cpp",
+      },
   };
   for (llvm::StringRef T : Tests) {
     SCOPED_TRACE(T);
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -306,6 +306,8 @@
   bool HasMore = Index.refs(RQuest, [&](const Ref &R) {
     if (AffectedFiles.size() > MaxLimitFiles)
       return;
+    if ((R.Kind & RefKind::Spelled) == RefKind::Unknown)
+      return;
     if (auto RefFilePath = filePath(R.Location, /*HintFilePath=*/MainFile)) {
       if (*RefFilePath != MainFile)
         AffectedFiles[*RefFilePath].push_back(toRange(R.Location));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74112.242844.patch
Type: text/x-patch
Size: 1787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200206/4f32ad83/attachment-0001.bin>


More information about the cfe-commits mailing list