[clang-tools-extra] [clangd] Store documentation when indexing standard library (PR #133681)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Sun May 4 23:21:22 PDT 2025


================
@@ -158,6 +159,42 @@ TEST(StdLibTests, EndToEnd) {
       UnorderedElementsAre(StdlibSymbol("list"), StdlibSymbol("vector")));
 }
 
+TEST(StdLibTests, StdLibDocComments) {
+  Config Cfg;
+  Cfg.Index.StandardLibrary = true;
+  WithContextValue Enabled(Config::Key, std::move(Cfg));
+
+  MockFS FS;
+  FS.Files["stdlib/vector"] = R"cpp(
+    namespace std {
+      struct vector {
+        /**doc comment*/
+        struct inner {};
+      };
+    }
+  )cpp";
+  MockCompilationDatabase CDB;
+  CDB.ExtraClangFlags.push_back("-isystem" + testPath("stdlib"));
+  ClangdServer::Options Opts = ClangdServer::optsForTest();
+  Opts.BuildDynamicSymbolIndex = true; // also used for stdlib index
+  ClangdServer Server(CDB, FS, Opts);
+
+  // Open an empty file. <vector> will not be part of the preamble index,
+  // but it will be part of the stdlib index.
+  Server.addDocument(testPath("foo.cc"), "");
+
+  // Wait for the stdlib index to be built.
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+
+  // Check that the index contains the doc comment.
+  FuzzyFindRequest Req;
+  Req.Query = "inner";
+  Req.Scopes = {"std::vector::"};
+  SymbolSlab Result = runFuzzyFind(*Server.getIndexForTest(), Req);
----------------
kadircet wrote:

FWIW, it might be better to use `runCustomAction` from syncapi (we should have index in the inputs).

https://github.com/llvm/llvm-project/pull/133681


More information about the cfe-commits mailing list