[PATCH] D54202: [clangd] Drop namespace references in the index.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 7 05:06:15 PST 2018


hokein updated this revision to Diff 172926.
hokein added a comment.

Fix a typo.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54202

Files:
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  unittests/clangd/SymbolCollectorTests.cpp


Index: unittests/clangd/SymbolCollectorTests.cpp
===================================================================
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -443,6 +443,8 @@
   };
   class $bar[[Bar]];
   void $func[[func]]();
+
+  namespace $ns[[NS]] {} // namespace ref is ignored
   )");
   Annotations Main(R"(
   class $bar[[Bar]] {};
@@ -474,6 +476,7 @@
                                   HaveRanges(Main.ranges("bar")))));
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "func").ID,
                                   HaveRanges(Main.ranges("func")))));
+  EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _))));
   // Symbols *only* in the main file (a, b, c) had no refs collected.
   auto MainSymbols =
       TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
Index: clangd/index/SymbolCollector.h
===================================================================
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -56,6 +56,9 @@
     bool CountReferences = false;
     /// The symbol ref kinds that will be collected.
     /// If not set, SymbolCollector will not collect refs.
+    /// Note that references of namespace decls are not collected, as they
+    /// contribute large part of the index, anbd they are less useful compared
+    /// with other decls.
     RefKind RefFilter = RefKind::Unknown;
     /// If set to true, SymbolCollector will collect all refs (from main file
     /// and included headers); otherwise, only refs from main file will be
Index: clangd/index/SymbolCollector.cpp
===================================================================
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -356,7 +356,7 @@
     return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
     return true;
-  if (CollectRef &&
+  if (CollectRef && !isa<NamespaceDecl>(ND) &&
       (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID()))
     DeclRefs[ND].emplace_back(SpellingLoc, Roles);
   // Don't continue indexing if this is a mere reference.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54202.172926.patch
Type: text/x-patch
Size: 2140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181107/e5bef43d/attachment.bin>


More information about the cfe-commits mailing list