ClangCodeModel: Inform clangd about changes to non-open files

That is, project-wide changes done from Qt Creator, such as search/
replace or quickfixes.

Fixes: QTCREATORBUG-26523
Change-Id: Ide4e56a7a1300eb6f25cabf1cfd94624d66e7e4e
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-11-05 15:35:54 +01:00
parent bcc5c9a344
commit 9a16eb5fe6
2 changed files with 25 additions and 1 deletions

View File

@@ -112,6 +112,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
m_instance = this;
watchForExternalChanges();
watchForInternalChanges();
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
@@ -488,6 +489,29 @@ void ClangModelManagerSupport::watchForExternalChanges()
});
}
void ClangModelManagerSupport::watchForInternalChanges()
{
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally,
this, [this](const Utils::FilePaths &filePaths) {
for (const Utils::FilePath &fp : filePaths) {
ClangdClient * const client = clientForFile(fp);
if (!client || client->documentForFilePath(fp))
continue;
client->openExtraFile(fp);
// We need to give clangd some time to start re-parsing the file.
// Closing right away does not work, and neither does doing it queued.
// If it turns out that this delay is not always enough, we'll need to come up
// with something more clever.
// Ideally, clangd would implement workspace/didChangeWatchedFiles; let's keep
// any eye on that.
QTimer::singleShot(5000, client, [client, fp] {
if (!client->documentForFilePath(fp))
client->closeExtraFile(fp); });
}
});
}
void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
{
QTC_ASSERT(editor, return);