[PATCH] D108119: Wiring of standard library indexing into clangd.

Christian Kühnel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 20 02:04:48 PDT 2021


kuhnel updated this revision to Diff 367738.
kuhnel added a comment.

addressed some review comments

question of integration with main functionality still open.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108119

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -484,6 +484,18 @@
     init(true),
 };
 
+opt<bool> IndexStandardLibrary{
+    "index-standard-library",
+    cat(Features),
+    desc("Background index should always include the STL headers even if \n"
+         "not used at the moment. This will enable code completion and \n"
+         "include fixer."
+         "WARNING: This option is experimental only, and will be removed "
+         "eventually. Don't rely on it"),
+    init(false),
+    Hidden,
+};
+
 std::function<void()> getMemoryCleanupFunction() {
   if (!EnableMallocTrim)
     return nullptr;
@@ -912,6 +924,7 @@
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
     Opts.Encoding = ForceOffsetEncoding;
 
+  Opts.IndexStandardLibrary = IndexStandardLibrary;
   if (CheckFile.getNumOccurrences()) {
     llvm::SmallString<256> Path;
     if (auto Error =
Index: clang-tools-extra/clangd/ClangdServer.h
===================================================================
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -24,6 +24,7 @@
 #include "index/Background.h"
 #include "index/FileIndex.h"
 #include "index/Index.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Cancellation.h"
@@ -167,7 +168,11 @@
     FeatureModuleSet *FeatureModules = nullptr;
 
     explicit operator TUScheduler::Options() const;
+
+    // Automatically index the standard library - experimental feature
+    bool IndexStandardLibrary = false;
   };
+
   // Sensible default options for use in tests.
   // Features like indexing must be enabled if desired.
   static Options optsForTest();
@@ -403,6 +408,8 @@
   std::unique_ptr<BackgroundIndex> BackgroundIdx;
   // Storage for merged views of the various indexes.
   std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
+  // If present, the index of the standard library.
+  std::unique_ptr<SymbolIndex> StandardLibraryIdx;
 
   // When set, provides clang-tidy options for a specific file.
   TidyProviderRef ClangTidyProvider;
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -27,6 +27,7 @@
 #include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/Merge.h"
+#include "index/StdLib.h"
 #include "refactor/Rename.h"
 #include "refactor/Tweak.h"
 #include "support/Logger.h"
@@ -175,6 +176,14 @@
       this->Index = Idx;
     }
   };
+  if (Opts.IndexStandardLibrary) {
+    StandardLibraryIdx = indexStandardLibrary(TFS);
+    if (!StandardLibraryIdx) {
+      elog("Unable to build standard library index. Not using it.");
+    } else {
+      AddIndex(StandardLibraryIdx.get());
+    }
+  }
   if (Opts.StaticIndex)
     AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108119.367738.patch
Type: text/x-patch
Size: 3114 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210820/9a2c375b/attachment-0001.bin>


More information about the cfe-commits mailing list