[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-27 Thread David Goldman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60249c2c3b9e: [clangd] Only re-open files if their flags 
changed (authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/test/did-change-configuration-params.test


Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -123,10 +124,10 @@
   /// produce '->' and '::', respectively.
   bool shouldRunCompletion(const CompletionParams ) 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 llvm::StringSet<> );
   void applyConfiguration(const ConfigurationSettings );
 
   /// 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
@@ -1126,10 +1126,8 @@
 void ClangdLSPServer::applyConfiguration(
 const ConfigurationSettings ) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  llvm::StringSet<> ModifiedFiles;
   for (auto  : Settings.compilationDatabaseChanges) {
-/// The opened files need to be reparsed only when some existing
-/// entries are changed.
 PathRef File = Entry.first;
 auto Old = CDB->getCompileCommand(File);
 auto New =
@@ -1138,11 +1136,11 @@
 /*Output=*/"");
 if (Old != New) {
   CDB->setCompileCommand(File, std::move(New));
-  ShouldReparseOpenFiles = true;
+  ModifiedFiles.insert(File);
 }
   }
-  if (ShouldReparseOpenFiles)
-reparseOpenedFiles();
+
+  reparseOpenedFiles(ModifiedFiles);
 }
 
 void ClangdLSPServer::publishSemanticHighlighting(
@@ -1463,10 +1461,15 @@
   notify("textDocument/clangd.fileStatus", Status.render(File));
 }
 
-void ClangdLSPServer::reparseOpenedFiles() {
+void ClangdLSPServer::reparseOpenedFiles(
+const llvm::StringSet<> ) {
+  if (ModifiedFiles.empty())
+return;
+  // Reparse only opened files that were modified.
   for (const Path  : 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/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -123,10 +124,10 @@
   /// produce '->' and '::', respectively.
   bool 

[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 239907.
dgoldman added a comment.

- Swap to stringset and simpler way of tracking modified files


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/test/did-change-configuration-params.test


Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -122,10 +123,10 @@
   /// produce '->' and '::', respectively.
   bool shouldRunCompletion(const CompletionParams ) 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 llvm::StringSet<> );
   void applyConfiguration(const ConfigurationSettings );
 
   /// 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,10 +1122,8 @@
 void ClangdLSPServer::applyConfiguration(
 const ConfigurationSettings ) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  llvm::StringSet<> ModifiedFiles;
   for (auto  : Settings.compilationDatabaseChanges) {
-/// The opened files need to be reparsed only when some existing
-/// entries are changed.
 PathRef File = Entry.first;
 auto Old = CDB->getCompileCommand(File);
 auto New =
@@ -1134,11 +1132,11 @@
 /*Output=*/"");
 if (Old != New) {
   CDB->setCompileCommand(File, std::move(New));
-  ShouldReparseOpenFiles = true;
+  ModifiedFiles.insert(File);
 }
   }
-  if (ShouldReparseOpenFiles)
-reparseOpenedFiles();
+
+  reparseOpenedFiles(ModifiedFiles);
 }
 
 void ClangdLSPServer::publishSemanticHighlighting(
@@ -1391,10 +1389,15 @@
   notify("textDocument/clangd.fileStatus", Status.render(File));
 }
 
-void ClangdLSPServer::reparseOpenedFiles() {
+void ClangdLSPServer::reparseOpenedFiles(
+const llvm::StringSet<> ) {
+  if (ModifiedFiles.empty())
+return;
+  // Reparse only opened files that were modified.
   for (const Path  : 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/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -122,10 +123,10 @@
   /// produce '->' and '::', respectively.
   bool shouldRunCompletion(const CompletionParams ) 

[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D72647#1833203 , @sammccall wrote:

> Let's make the minimal change here and land this.


Done


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Let's make the minimal change here and land this.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1126
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {

dgoldman wrote:
> sammccall wrote:
> > this is a clever technique. (Why not just use compilationDatabaseChanges 
> > directly? I suppose because then you have to deal more with path 
> > canonicalization?)
> > 
> > it risks having the CDB change concurrently and reloading those files too, 
> > though.
> > I guess there's not much harm in it. But in that case, why aren't we just 
> > permanently subscribing to CDB changes and re-parsing affected files? Lack 
> > of a thread to do it on?
> Yeah I think `compilationDatabaseChanges` would be equivalent to what is here 
> now, I can just swap to that.
> 
> For the perma subscribe I wasn't sure of the threading. If addDocument is 
> thread safe I think we're okay to just call `Server->AddDocument` from 
> whatever thread without holding a mutex?
ClangdServer isn't threadsafe, that's a good point.

> Yeah I think compilationDatabaseChanges would be equivalent to what is here 
> now, I can just swap to that.
This is the minimal change, let's do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-14 Thread David Goldman via Phabricator via cfe-commits
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1126
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {

sammccall wrote:
> this is a clever technique. (Why not just use compilationDatabaseChanges 
> directly? I suppose because then you have to deal more with path 
> canonicalization?)
> 
> it risks having the CDB change concurrently and reloading those files too, 
> though.
> I guess there's not much harm in it. But in that case, why aren't we just 
> permanently subscribing to CDB changes and re-parsing affected files? Lack of 
> a thread to do it on?
Yeah I think `compilationDatabaseChanges` would be equivalent to what is here 
now, I can just swap to that.

For the perma subscribe I wasn't sure of the threading. If addDocument is 
thread safe I think we're okay to just call `Server->AddDocument` from whatever 
thread without holding a mutex?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1125
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  std::set ModifiedFiles;
+  auto Sub =

nit: llvm::StringSet<> or DenseSet are the usual type here



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1126
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {

this is a clever technique. (Why not just use compilationDatabaseChanges 
directly? I suppose because then you have to deal more with path 
canonicalization?)

it risks having the CDB change concurrently and reloading those files too, 
though.
I guess there's not much harm in it. But in that case, why aren't we just 
permanently subscribing to CDB changes and re-parsing affected files? Lack of a 
thread to do it on?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61796 tests passed, 0 failed 
and 781 were skipped.

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-13 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 237791.
dgoldman added a comment.

- Fix broken did-change-configuration test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/test/did-change-configuration-params.test


Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
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 ) 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 );
   void applyConfiguration(const ConfigurationSettings );
 
   /// 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 ) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {
+ModifiedFiles.insert(Changes.begin(), Changes.end());
+  });
   for (auto  : 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 ) {
+  if (ModifiedFiles.empty())
+return;
+  // Reparse only opened files that were modified.
   for (const Path  : 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/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
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 ) 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 

[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-13 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon times-circle color=red} Unit tests: fail. 61795 tests passed, 1 failed 
and 781 were skipped.

  failed: Clangd.Clangd/did-change-configuration-params.test

{icon question-circle color=gray} clang-tidy: unknown.

{icon check-circle color=green} clang-format: pass.

Build artifacts 
: 
diff.json 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72647/new/

https://reviews.llvm.org/D72647



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-13 Thread David Goldman via Phabricator via cfe-commits
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 ) 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 );
   void applyConfiguration(const ConfigurationSettings );
 
   /// 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 ) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {
+ModifiedFiles.insert(Changes.begin(), Changes.end());
+  });
   for (auto  : 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 ) {
+  if (ModifiedFiles.empty())
+return;
+  // Reparse only opened files that were modified.
   for (const Path  : 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 ) 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 );
   void applyConfiguration(const ConfigurationSettings );
 
   /// 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 ) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  std::set ModifiedFiles;
+  auto Sub =
+  CDB->watch([](const std::vector Changes) {
+ModifiedFiles.insert(Changes.begin(), Changes.end());
+  });
   for (auto  : 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