forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user