[clang-tools-extra] r305376 - [clangd] Add a filename parameter to FileSystemProvider.

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 14 02:46:45 PDT 2017


Author: ibiryukov
Date: Wed Jun 14 04:46:44 2017
New Revision: 305376

URL: http://llvm.org/viewvc/llvm-project?rev=305376&view=rev
Log:
[clangd] Add a filename parameter to FileSystemProvider.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D34151

Modified:
    clang-tools-extra/trunk/clangd/ClangdServer.cpp
    clang-tools-extra/trunk/clangd/ClangdServer.h
    clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=305376&r1=305375&r2=305376&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jun 14 04:46:44 2017
@@ -59,7 +59,7 @@ Position clangd::offsetToPosition(String
 }
 
 Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
-RealFileSystemProvider::getTaggedFileSystem() {
+RealFileSystemProvider::getTaggedFileSystem(PathRef File) {
   return make_tagged(vfs::getRealFileSystem(), VFSTag());
 }
 
@@ -156,7 +156,7 @@ void ClangdServer::addDocument(PathRef F
 
     assert(FileContents.Draft &&
            "No contents inside a file that was scheduled for reparse");
-    auto TaggedFS = FSProvider.getTaggedFileSystem();
+    auto TaggedFS = FSProvider.getTaggedFileSystem(FileStr);
     Units.runOnUnit(
         FileStr, *FileContents.Draft, CDB, PCHs, TaggedFS.Value,
         [&](ClangdUnit const &Unit) {
@@ -197,7 +197,7 @@ ClangdServer::codeComplete(PathRef File,
   }
 
   std::vector<CompletionItem> Result;
-  auto TaggedFS = FSProvider.getTaggedFileSystem();
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
   // It would be nice to use runOnUnitWithoutReparse here, but we can't
   // guarantee the correctness of code completion cache here if we don't do the
   // reparse.

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=305376&r1=305375&r2=305376&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Jun 14 04:46:44 2017
@@ -82,16 +82,21 @@ public:
 class FileSystemProvider {
 public:
   virtual ~FileSystemProvider() = default;
+  /// Called by ClangdServer to obtain a vfs::FileSystem to be used for parsing.
+  /// Name of the file that will be parsed is passed in \p File.
+  ///
   /// \return A filesystem that will be used for all file accesses in clangd.
   /// A Tag returned by this method will be propagated to all results of clangd
   /// that will use this filesystem.
-  virtual Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() = 0;
+  virtual Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
+  getTaggedFileSystem(PathRef File) = 0;
 };
 
 class RealFileSystemProvider : public FileSystemProvider {
 public:
   /// \return getRealFileSystem() tagged with default tag, i.e. VFSTag()
-  Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() override;
+  Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
+  getTaggedFileSystem(PathRef File) override;
 };
 
 class ClangdServer;

Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp?rev=305376&r1=305375&r2=305376&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Wed Jun 14 04:46:44 2017
@@ -172,9 +172,13 @@ public:
 
 class MockFSProvider : public FileSystemProvider {
 public:
-  Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> getTaggedFileSystem() override {
+  Tagged<IntrusiveRefCntPtr<vfs::FileSystem>>
+  getTaggedFileSystem(PathRef File) override {
     IntrusiveRefCntPtr<vfs::InMemoryFileSystem> MemFS(
         new vfs::InMemoryFileSystem);
+    if (ExpectedFile)
+      EXPECT_EQ(*ExpectedFile, File);
+
     for (auto &FileAndContents : Files)
       MemFS->addFile(FileAndContents.first(), time_t(),
                      llvm::MemoryBuffer::getMemBuffer(FileAndContents.second,
@@ -186,6 +190,7 @@ public:
     return make_tagged(OverlayFS, Tag);
   }
 
+  llvm::Optional<SmallString<32>> ExpectedFile;
   llvm::StringMap<std::string> Files;
   VFSTag Tag = VFSTag();
 };
@@ -248,7 +253,10 @@ protected:
           FileWithContents.second;
 
     auto SourceFilename = getVirtualTestFilePath(SourceFileRelPath);
+
+    FS.ExpectedFile = SourceFilename;
     Server.addDocument(SourceFilename, SourceContents);
+
     auto Result = dumpASTWithoutMemoryLocs(Server, SourceFilename);
     EXPECT_EQ(ExpectErrors, DiagConsumer.hadErrorInLastDiags());
     return Result;
@@ -307,6 +315,7 @@ int b = a;
 
   FS.Files[FooH] = "int a;";
   FS.Files[FooCpp] = SourceContents;
+  FS.ExpectedFile = FooCpp;
 
   Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
@@ -342,6 +351,7 @@ int b = a;
 
   FS.Files[FooH] = "int a;";
   FS.Files[FooCpp] = SourceContents;
+  FS.ExpectedFile = FooCpp;
 
   Server.addDocument(FooCpp, SourceContents);
   auto DumpParse1 = dumpASTWithoutMemoryLocs(Server, FooCpp);
@@ -371,8 +381,9 @@ TEST_F(ClangdVFSTest, CheckVersions) {
   auto FooCpp = getVirtualTestFilePath("foo.cpp");
   const auto SourceContents = "int a;";
   FS.Files[FooCpp] = SourceContents;
-  FS.Tag = "123";
+  FS.ExpectedFile = FooCpp;
 
+  FS.Tag = "123";
   Server.addDocument(FooCpp, SourceContents);
   EXPECT_EQ(DiagConsumer.lastVFSTag(), FS.Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS.Tag);
@@ -419,6 +430,7 @@ int b =   ;
   // miss).
   Position CompletePos = {2, 8};
   FS.Files[FooCpp] = SourceContents;
+  FS.ExpectedFile = FooCpp;
 
   Server.addDocument(FooCpp, SourceContents);
 




More information about the cfe-commits mailing list