diff options
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 2 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/index/FileIndex.cpp | 10 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/index/FileIndex.h | 12 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/clangd/FileIndexTests.cpp | 4 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/clangd/IndexTests.cpp | 8 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/clangd/TestTU.cpp | 2 | 
6 files changed, 17 insertions, 21 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 6f2d13e0bd0..153dce29484 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -83,7 +83,7 @@ std::unique_ptr<ParsingCallbacks> makeUpdateCallbacks(FileIndex *FIndex) {      }      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/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp index ad7f6345f61..22a32ccab8d 100644 --- a/clang-tools-extra/clangd/index/FileIndex.cpp +++ b/clang-tools-extra/clangd/index/FileIndex.cpp @@ -65,10 +65,9 @@ indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,  }  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 @@ void FileIndex::updatePreamble(PathRef Path, ASTContext &AST,    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/clang-tools-extra/clangd/index/FileIndex.h b/clang-tools-extra/clangd/index/FileIndex.h index 421cfa4e863..7226e16680f 100644 --- a/clang-tools-extra/clangd/index/FileIndex.h +++ b/clang-tools-extra/clangd/index/FileIndex.h @@ -73,9 +73,9 @@ public:    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 @@ private:    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/clang-tools-extra/unittests/clangd/FileIndexTests.cpp b/clang-tools-extra/unittests/clangd/FileIndexTests.cpp index 346560acc02..f88355194ff 100644 --- a/clang-tools-extra/unittests/clangd/FileIndexTests.cpp +++ b/clang-tools-extra/unittests/clangd/FileIndexTests.cpp @@ -314,14 +314,14 @@ TEST(FileIndexTest, Refs) {    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/clang-tools-extra/unittests/clangd/IndexTests.cpp b/clang-tools-extra/unittests/clangd/IndexTests.cpp index 1f8129f52cd..b774742c375 100644 --- a/clang-tools-extra/unittests/clangd/IndexTests.cpp +++ b/clang-tools-extra/unittests/clangd/IndexTests.cpp @@ -244,7 +244,7 @@ TEST(MergeIndexTest, Refs) {    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(MergeIndexTest, Refs) {    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 @@ TEST(MergeIndexTest, Refs) {    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/clang-tools-extra/unittests/clangd/TestTU.cpp b/clang-tools-extra/unittests/clangd/TestTU.cpp index 847f7965734..4b610c8f959 100644 --- a/clang-tools-extra/unittests/clangd/TestTU.cpp +++ b/clang-tools-extra/unittests/clangd/TestTU.cpp @@ -51,7 +51,7 @@ SymbolSlab TestTU::headerSymbols() const {  // 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));  }  | 

