diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 42e77c11a34..a14fb81b901 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -686,6 +687,7 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client) // for the respective project to force re-parsing of open documents and re-indexing. // While this is not 100% bullet-proof, chances are good that in a typical session-based // workflow, e.g. a git branch switch will hit at least one open file. +// We also look for repository changes explicitly. void ClangModelManagerSupport::watchForExternalChanges() { connect(DocumentManager::instance(), &DocumentManager::filesChangedExternally, @@ -709,6 +711,23 @@ void ClangModelManagerSupport::watchForExternalChanges() return; } }); + + connect(VcsManager::instance(), &VcsManager::repositoryChanged, + this, [this](const FilePath &repoDir) { + if (sessionModeEnabled()) { + if (ClangdClient * const client = clientForProject(nullptr)) + scheduleClientRestart(client); + return; + } + for (const Project * const project : ProjectManager::projects()) { + const FilePath &projectDir = project->projectDirectory(); + if (repoDir == projectDir || repoDir.isChildOf(projectDir) + || projectDir.isChildOf(repoDir)) { + if (ClangdClient * const client = clientForProject(project)) + scheduleClientRestart(client); + } + } + }); } // If Qt Creator changes a file that is not open (e.g. as part of a quickfix), we have to