dgoldman created this revision. dgoldman added a reviewer: sammccall. Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D72647 Files: clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/ClangdLSPServer.h Index: clang-tools-extra/clangd/ClangdLSPServer.h =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.h +++ clang-tools-extra/clangd/ClangdLSPServer.h @@ -122,10 +122,10 @@ /// produce '->' and '::', respectively. bool shouldRunCompletion(const CompletionParams &Params) const; - /// Forces a reparse of all currently opened files. As a result, this method - /// may be very expensive. This method is normally called when the - /// compilation database is changed. - void reparseOpenedFiles(); + /// Forces a reparse of all currently opened files which were modified. As a + /// result, this method may be very expensive. This method is normally called + /// when the compilation database is changed. + void reparseOpenedFiles(const std::set<std::string> &ModifiedFiles); void applyConfiguration(const ConfigurationSettings &Settings); /// Sends a "publishSemanticHighlighting" notification to the LSP client. Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1122,7 +1122,11 @@ void ClangdLSPServer::applyConfiguration( const ConfigurationSettings &Settings) { // Per-file update to the compilation database. - bool ShouldReparseOpenFiles = false; + std::set<std::string> ModifiedFiles; + auto Sub = + CDB->watch([&ModifiedFiles](const std::vector<std::string> Changes) { + ModifiedFiles.insert(Changes.begin(), Changes.end()); + }); for (auto &Entry : Settings.compilationDatabaseChanges) { /// The opened files need to be reparsed only when some existing /// entries are changed. @@ -1134,11 +1138,10 @@ /*Output=*/""); if (Old != New) { CDB->setCompileCommand(File, std::move(New)); - ShouldReparseOpenFiles = true; } } - if (ShouldReparseOpenFiles) - reparseOpenedFiles(); + + reparseOpenedFiles(ModifiedFiles); } void ClangdLSPServer::publishSemanticHighlighting( @@ -1391,10 +1394,15 @@ notify("textDocument/clangd.fileStatus", Status.render(File)); } -void ClangdLSPServer::reparseOpenedFiles() { +void ClangdLSPServer::reparseOpenedFiles( + const std::set<std::string> &ModifiedFiles) { + if (ModifiedFiles.empty()) + return; + // Reparse only opened files that were modified. for (const Path &FilePath : DraftMgr.getActiveFiles()) - Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath), - WantDiagnostics::Auto); + if (ModifiedFiles.find(FilePath) != ModifiedFiles.end()) + Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath), + WantDiagnostics::Auto); } } // namespace clangd
Index: clang-tools-extra/clangd/ClangdLSPServer.h =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.h +++ clang-tools-extra/clangd/ClangdLSPServer.h @@ -122,10 +122,10 @@ /// produce '->' and '::', respectively. bool shouldRunCompletion(const CompletionParams &Params) const; - /// Forces a reparse of all currently opened files. As a result, this method - /// may be very expensive. This method is normally called when the - /// compilation database is changed. - void reparseOpenedFiles(); + /// Forces a reparse of all currently opened files which were modified. As a + /// result, this method may be very expensive. This method is normally called + /// when the compilation database is changed. + void reparseOpenedFiles(const std::set<std::string> &ModifiedFiles); void applyConfiguration(const ConfigurationSettings &Settings); /// Sends a "publishSemanticHighlighting" notification to the LSP client. Index: clang-tools-extra/clangd/ClangdLSPServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -1122,7 +1122,11 @@ void ClangdLSPServer::applyConfiguration( const ConfigurationSettings &Settings) { // Per-file update to the compilation database. - bool ShouldReparseOpenFiles = false; + std::set<std::string> ModifiedFiles; + auto Sub = + CDB->watch([&ModifiedFiles](const std::vector<std::string> Changes) { + ModifiedFiles.insert(Changes.begin(), Changes.end()); + }); for (auto &Entry : Settings.compilationDatabaseChanges) { /// The opened files need to be reparsed only when some existing /// entries are changed. @@ -1134,11 +1138,10 @@ /*Output=*/""); if (Old != New) { CDB->setCompileCommand(File, std::move(New)); - ShouldReparseOpenFiles = true; } } - if (ShouldReparseOpenFiles) - reparseOpenedFiles(); + + reparseOpenedFiles(ModifiedFiles); } void ClangdLSPServer::publishSemanticHighlighting( @@ -1391,10 +1394,15 @@ notify("textDocument/clangd.fileStatus", Status.render(File)); } -void ClangdLSPServer::reparseOpenedFiles() { +void ClangdLSPServer::reparseOpenedFiles( + const std::set<std::string> &ModifiedFiles) { + if (ModifiedFiles.empty()) + return; + // Reparse only opened files that were modified. for (const Path &FilePath : DraftMgr.getActiveFiles()) - Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath), - WantDiagnostics::Auto); + if (ModifiedFiles.find(FilePath) != ModifiedFiles.end()) + Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath), + WantDiagnostics::Auto); } } // namespace clangd
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits