Skip to content

Commit ff0c31d

Browse files
committed
[clangd] Build stdlib index similar to preamble
1 parent c536967 commit ff0c31d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

clang-tools-extra/clangd/index/StdLib.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
#include "Compiler.h"
1616
#include "Config.h"
1717
#include "SymbolCollector.h"
18+
#include "clang-include-cleaner/Record.h"
19+
#include "index/FileIndex.h"
1820
#include "index/IndexAction.h"
1921
#include "support/Logger.h"
2022
#include "support/ThreadsafeFS.h"
2123
#include "support/Trace.h"
2224
#include "clang/Basic/LangOptions.h"
2325
#include "clang/Frontend/CompilerInvocation.h"
26+
#include "clang/Frontend/FrontendActions.h"
2427
#include "clang/Lex/PreprocessorOptions.h"
2528
#include "clang/Tooling/Inclusions/StandardLibrary.h"
2629
#include "llvm/ADT/IntrusiveRefCntPtr.h"
@@ -234,22 +237,26 @@ SymbolSlab indexStandardLibrary(llvm::StringRef HeaderSources,
234237
// We end up "blessing" such headers, and can only do that by indexing
235238
// everything first.
236239

237-
// Refs, relations, include graph in the stdlib mostly aren't useful.
238-
auto Action = createStaticIndexingAction(
239-
IndexOpts, [&](SymbolSlab S) { Symbols = std::move(S); }, nullptr,
240-
nullptr, nullptr);
240+
SyntaxOnlyAction Action;
241241

242-
if (!Action->BeginSourceFile(*Clang, Input)) {
242+
if (!Action.BeginSourceFile(*Clang, Input)) {
243243
elog("Standard Library Index: BeginSourceFile() failed");
244244
return Symbols;
245245
}
246246

247-
if (llvm::Error Err = Action->Execute()) {
247+
if (llvm::Error Err = Action.Execute()) {
248248
elog("Standard Library Index: Execute failed: {0}", std::move(Err));
249249
return Symbols;
250250
}
251251

252-
Action->EndSourceFile();
252+
// We don't care about include graph for stdlib headers, so provide a no-op
253+
// PI.
254+
include_cleaner::PragmaIncludes PI;
255+
auto Slabs = indexHeaderSymbols("", Clang->getASTContext(),
256+
Clang->getPreprocessor(), PI);
257+
Symbols = std::move(std::get<0>(Slabs));
258+
259+
Action.EndSourceFile();
253260

254261
unsigned SymbolsBeforeFilter = Symbols.size();
255262
Symbols = filter(std::move(Symbols), Loc);

0 commit comments

Comments
 (0)