forked from qt-creator/qt-creator
ClangCodeModel: Restart clangd on changes in VCS repository
This should prevent the index from becoming stale after e.g. a git checkout. Change-Id: I94d364d3f2ec38889564c7859ca95ccb2de3019d Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/session.h>
|
||||
#include <coreplugin/vcsmanager.h>
|
||||
|
||||
#include <cppeditor/cppcodemodelsettings.h>
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user