nridge created this revision.
nridge added reviewers: hokein, kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Some projects, like the Linux kernel, make extensive use of such
identifiers, making it a usability if they can't be indexed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153946

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp

Index: clang-tools-extra/clangd/refactor/Rename.cpp
===================================================================
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -8,6 +8,7 @@
 
 #include "refactor/Rename.h"
 #include "AST.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "ParsedAST.h"
 #include "Selection.h"
@@ -234,9 +235,10 @@
   else if (!DeclaredInMainFile)
     IsMainFileOnly = false;
   // If the symbol is not indexable, we disallow rename.
+  SymbolCollector::Options Options;
+  Options.CollectReserved = Config::current().Index.ReservedIdentifiers;
   if (!SymbolCollector::shouldCollectSymbol(
-          RenameDecl, RenameDecl.getASTContext(), SymbolCollector::Options(),
-          IsMainFileOnly))
+          RenameDecl, RenameDecl.getASTContext(), Options, IsMainFileOnly))
     return ReasonToReject::NonIndexable;
 
   return std::nullopt;
Index: clang-tools-extra/clangd/indexer/IndexerMain.cpp
===================================================================
--- clang-tools-extra/clangd/indexer/IndexerMain.cpp
+++ clang-tools-extra/clangd/indexer/IndexerMain.cpp
@@ -45,6 +45,8 @@
   std::unique_ptr<FrontendAction> create() override {
     SymbolCollector::Options Opts;
     Opts.CountReferences = true;
+    // FIXME: Do we have access to Config here? If so, should we respect
+    // Index.ReservedIdentifiers?
     Opts.FileFilter = [&](const SourceManager &SM, FileID FID) {
       const auto F = SM.getFileEntryRefForID(FID);
       if (!F)
Index: clang-tools-extra/clangd/index/StdLib.cpp
===================================================================
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -230,6 +230,7 @@
   IndexOpts.CollectMainFileRefs = false;
   IndexOpts.CollectMacro = true;
   IndexOpts.StoreAllDocumentation = true;
+  // FIXME: Should we respect the Index.ReservedIdentifiers config here?
   // Sadly we can't use IndexOpts.FileFilter to restrict indexing scope.
   // Files from outside the StdLibLocation may define true std symbols anyway.
   // We end up "blessing" such headers, and can only do that by indexing
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -8,6 +8,7 @@
 
 #include "FileIndex.h"
 #include "CollectMacros.h"
+#include "Config.h"
 #include "ParsedAST.h"
 #include "index/CanonicalIncludes.h"
 #include "index/Index.h"
@@ -57,7 +58,8 @@
   CollectorOpts.CollectMainFileRefs = CollectMainFileRefs;
   // We want stdlib implementation details in the index only if we've opened the
   // file in question. This does means xrefs won't work, though.
-  CollectorOpts.CollectReserved = IsIndexMainAST;
+  CollectorOpts.CollectReserved =
+      IsIndexMainAST || Config::current().Index.ReservedIdentifiers;
 
   index::IndexingOptions IndexOpts;
   // We only need declarations, because we don't count references.
Index: clang-tools-extra/clangd/index/Background.cpp
===================================================================
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -304,6 +304,7 @@
     return true;
   };
   IndexOpts.CollectMainFileRefs = true;
+  IndexOpts.CollectReserved = Config::current().Index.ReservedIdentifiers;
 
   IndexFileIn Index;
   auto Action = createStaticIndexingAction(
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 #include "XRefs.h"
 #include "AST.h"
+#include "Config.h"
 #include "FindSymbols.h"
 #include "FindTarget.h"
 #include "Headers.h"
@@ -929,6 +930,7 @@
 
     SymbolCollector::Options CollectorOpts;
     CollectorOpts.CollectMainFileSymbols = true;
+    CollectorOpts.CollectReserved = Config::current().Index.ReservedIdentifiers;
     for (SourceLocation L : Locs) {
       L = SM.getFileLoc(L);
       if (const auto *Tok = TB.spelledTokenAt(L))
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -335,8 +335,9 @@
 
   // Skip querying for non-indexable symbols, there's no point.
   // We're searching for symbols that might be indexed outside this main file.
-  if (!SymbolCollector::shouldCollectSymbol(ND, ND.getASTContext(),
-                                            SymbolCollector::Options(),
+  SymbolCollector::Options Opts;
+  Opts.CollectReserved = Config::current().Index.ReservedIdentifiers;
+  if (!SymbolCollector::shouldCollectSymbol(ND, ND.getASTContext(), Opts,
                                             /*IsMainFileOnly=*/false))
     return;
   auto ID = getSymbolID(&ND);
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -194,6 +194,10 @@
       if (auto StandardLibrary = boolValue(N, "StandardLibrary"))
         F.StandardLibrary = *StandardLibrary;
     });
+    Dict.handle("ReservedIdentifiers", [&](Node &N) {
+      if (auto ReservedIdentifiers = boolValue(N, "ReservedIdentifiers"))
+        F.ReservedIdentifiers = *ReservedIdentifiers;
+    });
     Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===================================================================
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -199,9 +199,12 @@
       std::optional<Located<std::string>> MountPoint;
     };
     std::optional<Located<ExternalBlock>> External;
-    // Whether the standard library visible from this file should be indexed.
-    // This makes all standard library symbols available, included or not.
+    /// Whether the standard library visible from this file should be indexed.
+    /// This makes all standard library symbols available, included or not.
     std::optional<Located<bool>> StandardLibrary;
+    /// Whether identifiers reserved for use by the implementation (e.g.
+    /// beginning with two underscores) should be indexed.
+    std::optional<Located<bool>> ReservedIdentifiers;
   };
   IndexBlock Index;
 
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -337,6 +337,11 @@
           [Val(**F.StandardLibrary)](const Params &, Config &C) {
             C.Index.StandardLibrary = Val;
           });
+    if (F.ReservedIdentifiers)
+      Out.Apply.push_back(
+          [Val(**F.ReservedIdentifiers)](const Params &, Config &C) {
+            C.Index.ReservedIdentifiers = Val;
+          });
   }
 
   void compile(Fragment::IndexBlock::ExternalBlock &&External,
Index: clang-tools-extra/clangd/Config.h
===================================================================
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -86,6 +86,7 @@
     BackgroundPolicy Background = BackgroundPolicy::Build;
     ExternalIndexSpec External;
     bool StandardLibrary = true;
+    bool ReservedIdentifiers = false;
   } Index;
 
   enum class IncludesPolicy {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to