[PATCH] D52979: [clangd] Add removeFile interface in FileIndex.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 8 03:36:57 PDT 2018


hokein updated this revision to Diff 168638.
hokein added a comment.

clang-format.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52979

Files:
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  unittests/clangd/FileIndexTests.cpp


Index: unittests/clangd/FileIndexTests.cpp
===================================================================
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -23,6 +23,7 @@
 using testing::_;
 using testing::AllOf;
 using testing::ElementsAre;
+using testing::IsEmpty;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -164,6 +165,17 @@
   EXPECT_THAT(match(M, Req), UnorderedElementsAre("ns::f", "ns::X"));
 }
 
+TEST(FileIndexTest, RemoveFile) {
+  FileIndex M;
+  update(M, "f1", "class Foo {};");
+
+  FuzzyFindRequest Req;
+  EXPECT_THAT(match(M, Req), UnorderedElementsAre("Foo"));
+
+  M.removeFile("f1.cpp");
+  EXPECT_THAT(match(M, Req), IsEmpty());
+}
+
 TEST(FileIndexTest, NoLocal) {
   FileIndex M;
   update(M, "f1", "namespace ns { void f() { int local = 0; } class X {}; }");
Index: clangd/index/FileIndex.h
===================================================================
--- clangd/index/FileIndex.h
+++ clangd/index/FileIndex.h
@@ -59,7 +59,6 @@
 };
 
 /// This manages symbols from files and an in-memory index on all symbols.
-/// FIXME: Expose an interface to remove files that are closed.
 class FileIndex : public MergedIndex {
 public:
   /// If URISchemes is empty, the default schemes in SymbolCollector will be
@@ -75,6 +74,9 @@
   /// `indexMainDecls`.
   void updateMain(PathRef Path, ParsedAST &AST);
 
+  /// Remove all index data associated with the file \p Path.
+  void removeFile(PathRef Path);
+
 private:
   std::vector<std::string> URISchemes;
 
Index: clangd/index/FileIndex.cpp
===================================================================
--- clangd/index/FileIndex.cpp
+++ clangd/index/FileIndex.cpp
@@ -174,5 +174,12 @@
   MainFileIndex.reset(MainFileSymbols.buildMemIndex());
 }
 
+void FileIndex::removeFile(PathRef Path) {
+  PreambleSymbols.update(Path, nullptr, nullptr);
+  PreambleIndex.reset(PreambleSymbols.buildMemIndex());
+  MainFileSymbols.update(Path, nullptr, nullptr);
+  MainFileIndex.reset(MainFileSymbols.buildMemIndex());
+}
+
 } // namespace clangd
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52979.168638.patch
Type: text/x-patch
Size: 2096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181008/56f322d4/attachment.bin>


More information about the cfe-commits mailing list