[clangd] Get rid of Decls parameter in indexMainDecls. NFC
It's already available in ParsedAST.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@342473 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/ClangdServer.cpp b/clangd/ClangdServer.cpp
index 6f2d13e..153dce2 100644
--- a/clangd/ClangdServer.cpp
+++ b/clangd/ClangdServer.cpp
@@ -83,7 +83,7 @@
}
void onMainAST(PathRef Path, ParsedAST &AST) override {
- FIndex->updateMain(Path, AST, AST.getLocalTopLevelDecls());
+ FIndex->updateMain(Path, AST);
}
};
return llvm::make_unique<CB>(FIndex);
diff --git a/clangd/index/FileIndex.cpp b/clangd/index/FileIndex.cpp
index ad7f634..22a32cc 100644
--- a/clangd/index/FileIndex.cpp
+++ b/clangd/index/FileIndex.cpp
@@ -65,10 +65,9 @@
}
std::pair<SymbolSlab, RefSlab>
-indexMainDecls(ParsedAST &AST, llvm::ArrayRef<Decl *> TopLevelDecls,
- llvm::ArrayRef<std::string> URISchemes) {
+indexMainDecls(ParsedAST &AST, llvm::ArrayRef<std::string> URISchemes) {
return indexSymbols(AST.getASTContext(), AST.getPreprocessorPtr(),
- TopLevelDecls,
+ AST.getLocalTopLevelDecls(),
/*IsIndexMainAST=*/true, URISchemes);
}
@@ -163,9 +162,8 @@
PreambleIndex.reset(PreambleSymbols.buildMemIndex());
}
-void FileIndex::updateMain(PathRef Path, ParsedAST &AST,
- llvm::ArrayRef<Decl *> TopLevelDecls) {
- auto Contents = indexMainDecls(AST, TopLevelDecls, URISchemes);
+void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
+ auto Contents = indexMainDecls(AST, URISchemes);
MainFileSymbols.update(
Path, llvm::make_unique<SymbolSlab>(std::move(Contents.first)),
llvm::make_unique<RefSlab>(std::move(Contents.second)));
diff --git a/clangd/index/FileIndex.h b/clangd/index/FileIndex.h
index 421cfa4..7226e16 100644
--- a/clangd/index/FileIndex.h
+++ b/clangd/index/FileIndex.h
@@ -73,9 +73,9 @@
void updatePreamble(PathRef Path, ASTContext &AST,
std::shared_ptr<Preprocessor> PP);
- /// Update symbols from main file \p Path with symbols in \p TopLevelDecls.
- void updateMain(PathRef Path, ParsedAST &AST,
- llvm::ArrayRef<Decl *> TopLevelDecls);
+ /// Update symbols and references from main file \p Path with
+ /// `indexMainDecls`.
+ void updateMain(PathRef Path, ParsedAST &AST);
private:
std::vector<std::string> URISchemes;
@@ -106,12 +106,12 @@
std::unique_ptr<SymbolIndex> MergedIndex; // Merge preamble and main index.
};
-/// Retrieves symbols and refs of \p Decls in \p AST.
+/// Retrieves symbols and refs of local top level decls in \p AST (i.e.
+/// `AST.getLocalTopLevelDecls()`).
/// Exposed to assist in unit tests.
/// If URISchemes is empty, the default schemes in SymbolCollector will be used.
std::pair<SymbolSlab, RefSlab>
-indexMainDecls(ParsedAST &AST, llvm::ArrayRef<Decl *> Decls,
- llvm::ArrayRef<std::string> URISchemes = {});
+indexMainDecls(ParsedAST &AST, llvm::ArrayRef<std::string> URISchemes = {});
/// Idex declarations from \p AST and macros from \p PP that are declared in
/// included headers.
diff --git a/unittests/clangd/FileIndexTests.cpp b/unittests/clangd/FileIndexTests.cpp
index 346560a..f883551 100644
--- a/unittests/clangd/FileIndexTests.cpp
+++ b/unittests/clangd/FileIndexTests.cpp
@@ -314,14 +314,14 @@
Test.Code = MainCode.code();
Test.Filename = "test.cc";
auto AST = Test.build();
- Index.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
+ Index.updateMain(Test.Filename, AST);
// Add test2.cc
TestTU Test2;
Test2.HeaderCode = HeaderCode;
Test2.Code = MainCode.code();
Test2.Filename = "test2.cc";
AST = Test2.build();
- Index.updateMain(Test2.Filename, AST, AST.getLocalTopLevelDecls());
+ Index.updateMain(Test2.Filename, AST);
EXPECT_THAT(getRefs(Index.index(), Foo.ID),
RefsAre({AllOf(RefRange(MainCode.range("foo")),
diff --git a/unittests/clangd/IndexTests.cpp b/unittests/clangd/IndexTests.cpp
index 1f8129f..b774742 100644
--- a/unittests/clangd/IndexTests.cpp
+++ b/unittests/clangd/IndexTests.cpp
@@ -244,7 +244,7 @@
Test.Code = Test1Code.code();
Test.Filename = "test.cc";
auto AST = Test.build();
- Dyn.updateMain(Test.Filename, AST, AST.getLocalTopLevelDecls());
+ Dyn.updateMain(Test.Filename, AST);
// Build static index for test.cc.
Test.HeaderCode = HeaderCode;
@@ -252,8 +252,7 @@
Test.Filename = "test.cc";
auto StaticAST = Test.build();
// Add stale refs for test.cc.
- StaticIndex.updateMain(Test.Filename, StaticAST,
- StaticAST.getLocalTopLevelDecls());
+ StaticIndex.updateMain(Test.Filename, StaticAST);
// Add refs for test2.cc
Annotations Test2Code(R"(class $Foo[[Foo]] {};)");
@@ -262,8 +261,7 @@
Test2.Code = Test2Code.code();
Test2.Filename = "test2.cc";
StaticAST = Test2.build();
- StaticIndex.updateMain(Test2.Filename, StaticAST,
- StaticAST.getLocalTopLevelDecls());
+ StaticIndex.updateMain(Test2.Filename, StaticAST);
RefsRequest Request;
Request.IDs = {Foo.ID};
diff --git a/unittests/clangd/TestTU.cpp b/unittests/clangd/TestTU.cpp
index 847f796..4b610c8 100644
--- a/unittests/clangd/TestTU.cpp
+++ b/unittests/clangd/TestTU.cpp
@@ -51,7 +51,7 @@
// FIXME: This should return a FileIndex with both preamble and main index.
std::unique_ptr<SymbolIndex> TestTU::index() const {
auto AST = build();
- auto Content = indexMainDecls(AST, AST.getLocalTopLevelDecls());
+ auto Content = indexMainDecls(AST);
return MemIndex::build(std::move(Content.first), std::move(Content.second));
}