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

Christian Kühnel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 17 04:00:36 PDT 2021


kuhnel updated this revision to Diff 366856.
kuhnel marked an inline comment as done.
kuhnel added a comment.

fixed lifecycle of StdLibIndex variable


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,16 @@
       this->Index = Idx;
     }
   };
+  if (Opts.IndexStandardLibrary) {
+    auto SLIndex = indexStandardLibrary(TFS);
+    if (!SLIndex) {
+      elog("Unable to build standard library index. Not using it.");
+      elog(toString(SLIndex.takeError()).c_str());
+    } else {
+      StandardLibraryIdx = std::move(SLIndex.get());
+      AddIndex(StandardLibraryIdx.get());
+    }
+  }
   if (Opts.StaticIndex)
     AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108119.366856.patch
Type: text/x-patch
Size: 3203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210817/9ea4bd8b/attachment.bin>


More information about the cfe-commits mailing list