[clang-tools-extra] r345231 - [clangd] Don't invalidate LSP-set compile commands when closing a file.

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 24 19:04:30 PDT 2018


Author: sammccall
Date: Wed Oct 24 19:04:30 2018
New Revision: 345231

URL: http://llvm.org/viewvc/llvm-project?rev=345231&view=rev
Log:
[clangd] Don't invalidate LSP-set compile commands when closing a file.

Summary:
It doesn't make much sense: setting them is not coupled to opening the file,
it's an asynchronous notification.

I don't think this is a breaking change - this behavior is hard to observe!

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

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

Modified:
    clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
    clang-tools-extra/trunk/clangd/ClangdLSPServer.h
    clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
    clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=345231&r1=345230&r2=345231&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Oct 24 19:04:30 2018
@@ -393,7 +393,6 @@ void ClangdLSPServer::onDocumentDidChang
     // fail rather than giving wrong results.
     DraftMgr.removeDraft(File);
     Server->removeDocument(File);
-    CDB->invalidate(File);
     elog("Failed to update {0}: {1}", File, Contents.takeError());
     return;
   }
@@ -489,7 +488,6 @@ void ClangdLSPServer::onDocumentDidClose
   PathRef File = Params.textDocument.uri.file();
   DraftMgr.removeDraft(File);
   Server->removeDocument(File);
-  CDB->invalidate(File);
 }
 
 void ClangdLSPServer::onDocumentOnTypeFormatting(
@@ -804,11 +802,6 @@ ClangdLSPServer::CompilationDB::makeDire
                        /*IsDirectoryBased=*/true);
 }
 
-void ClangdLSPServer::CompilationDB::invalidate(PathRef File) {
-  if (!IsDirectoryBased)
-    static_cast<InMemoryCompilationDb *>(CDB.get())->invalidate(File);
-}
-
 bool ClangdLSPServer::CompilationDB::setCompilationCommandForFile(
     PathRef File, tooling::CompileCommand CompilationCommand) {
   if (IsDirectoryBased) {

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=345231&r1=345230&r2=345231&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Oct 24 19:04:30 2018
@@ -113,8 +113,6 @@ private:
     static CompilationDB
     makeDirectoryBased(llvm::Optional<Path> CompileCommandsDir);
 
-    void invalidate(PathRef File);
-
     /// Sets the compilation command for a particular file.
     /// Only valid for in-memory CDB, no-op and error log on DirectoryBasedCDB.
     ///

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=345231&r1=345230&r2=345231&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Wed Oct 24 19:04:30 2018
@@ -135,10 +135,5 @@ bool InMemoryCompilationDb::setCompilati
   return false;
 }
 
-void InMemoryCompilationDb::invalidate(PathRef File) {
-  std::unique_lock<std::mutex> Lock(Mutex);
-  Commands.erase(File);
-}
-
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=345231&r1=345230&r2=345231&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Wed Oct 24 19:04:30 2018
@@ -100,10 +100,6 @@ public:
   bool setCompilationCommandForFile(PathRef File,
                                     tooling::CompileCommand CompilationCommand);
 
-  /// Removes the compilation command for \p File if it's present in the
-  /// mapping.
-  void invalidate(PathRef File);
-
 private:
   mutable std::mutex Mutex;
   llvm::StringMap<tooling::CompileCommand> Commands; /* GUARDED_BY(Mut) */




More information about the cfe-commits mailing list