1111#include " Headers.h"
1212#include " clang-include-cleaner/Record.h"
1313#include " index/Relation.h"
14+ #include " index/Serialization.h"
1415#include " index/SymbolCollector.h"
1516#include " index/SymbolOrigin.h"
1617#include " clang/AST/ASTConsumer.h"
@@ -130,13 +131,8 @@ class IndexAction : public ASTFrontendAction {
130131 IndexAction (std::shared_ptr<SymbolCollector> C,
131132 std::unique_ptr<include_cleaner::PragmaIncludes> PI,
132133 const index::IndexingOptions &Opts,
133- std::function<void (SymbolSlab)> SymbolsCallback,
134- std::function<void (RefSlab)> RefsCallback,
135- std::function<void (RelationSlab)> RelationsCallback,
136- std::function<void (IncludeGraph)> IncludeGraphCallback)
137- : SymbolsCallback(SymbolsCallback), RefsCallback(RefsCallback),
138- RelationsCallback (RelationsCallback),
139- IncludeGraphCallback(IncludeGraphCallback), Collector(C),
134+ std::function<void (IndexFileIn)> IndexContentsCallback)
135+ : IndexContentsCallback(IndexContentsCallback), Collector(C),
140136 PI (std::move(PI)), Opts(Opts) {
141137 this ->Opts .ShouldTraverseDecl = [this ](const Decl *D) {
142138 // Many operations performed during indexing is linear in terms of depth
@@ -161,9 +157,8 @@ class IndexAction : public ASTFrontendAction {
161157 std::unique_ptr<ASTConsumer>
162158 CreateASTConsumer (CompilerInstance &CI, llvm::StringRef InFile) override {
163159 PI->record (CI.getPreprocessor ());
164- if (IncludeGraphCallback != nullptr )
165- CI.getPreprocessor ().addPPCallbacks (
166- std::make_unique<IncludeGraphCollector>(CI.getSourceManager (), IG));
160+ CI.getPreprocessor ().addPPCallbacks (
161+ std::make_unique<IncludeGraphCollector>(CI.getSourceManager (), IG));
167162
168163 return index::createIndexingASTConsumer (Collector, Opts,
169164 CI.getPreprocessorPtr ());
@@ -185,26 +180,21 @@ class IndexAction : public ASTFrontendAction {
185180 }
186181
187182 void EndSourceFileAction () override {
188- SymbolsCallback (Collector->takeSymbols ());
189- if (RefsCallback != nullptr )
190- RefsCallback (Collector->takeRefs ());
191- if (RelationsCallback != nullptr )
192- RelationsCallback (Collector->takeRelations ());
193- if (IncludeGraphCallback != nullptr ) {
183+ IndexFileIn Result;
184+ Result.Symbols = Collector->takeSymbols ();
185+ Result.Refs = Collector->takeRefs ();
186+ Result.Relations = Collector->takeRelations ();
194187#ifndef NDEBUG
195188 // This checks if all nodes are initialized.
196189 for (const auto &Node : IG)
197190 assert (Node.getKeyData () == Node.getValue ().URI .data ());
198191#endif
199- IncludeGraphCallback ( std::move (IG) );
200- }
192+ Result. Sources = std::move (IG);
193+ IndexContentsCallback ( std::move (Result));
201194 }
202195
203196private:
204- std::function<void (SymbolSlab)> SymbolsCallback;
205- std::function<void (RefSlab)> RefsCallback;
206- std::function<void (RelationSlab)> RelationsCallback;
207- std::function<void (IncludeGraph)> IncludeGraphCallback;
197+ std::function<void (IndexFileIn)> IndexContentsCallback;
208198 std::shared_ptr<SymbolCollector> Collector;
209199 std::unique_ptr<include_cleaner::PragmaIncludes> PI;
210200 index::IndexingOptions Opts;
@@ -215,10 +205,7 @@ class IndexAction : public ASTFrontendAction {
215205
216206std::unique_ptr<FrontendAction> createStaticIndexingAction (
217207 SymbolCollector::Options Opts,
218- std::function<void (SymbolSlab)> SymbolsCallback,
219- std::function<void(RefSlab)> RefsCallback,
220- std::function<void(RelationSlab)> RelationsCallback,
221- std::function<void(IncludeGraph)> IncludeGraphCallback) {
208+ std::function<void (IndexFileIn)> IndexContentsCallback) {
222209 index::IndexingOptions IndexOpts;
223210 IndexOpts.SystemSymbolFilter =
224211 index::IndexingOptions::SystemSymbolFilterKind::All;
@@ -231,16 +218,13 @@ std::unique_ptr<FrontendAction> createStaticIndexingAction(
231218 if (Opts.Origin == SymbolOrigin::Unknown)
232219 Opts.Origin = SymbolOrigin::Static;
233220 Opts.StoreAllDocumentation = false ;
234- if (RefsCallback != nullptr ) {
235- Opts.RefFilter = RefKind::All;
236- Opts.RefsInHeaders = true ;
237- }
221+ Opts.RefFilter = RefKind::All;
222+ Opts.RefsInHeaders = true ;
238223 auto PragmaIncludes = std::make_unique<include_cleaner::PragmaIncludes>();
239224 Opts.PragmaIncludes = PragmaIncludes.get ();
240225 return std::make_unique<IndexAction>(std::make_shared<SymbolCollector>(Opts),
241226 std::move (PragmaIncludes), IndexOpts,
242- SymbolsCallback, RefsCallback,
243- RelationsCallback, IncludeGraphCallback);
227+ IndexContentsCallback);
244228}
245229
246230} // namespace clangd
0 commit comments