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;
|
m_instance = this;
|
||||||
|
|
||||||
watchForExternalChanges();
|
watchForExternalChanges();
|
||||||
|
watchForInternalChanges();
|
||||||
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
|
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
|
||||||
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
||||||
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
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)
|
void ClangModelManagerSupport::onEditorOpened(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(editor, return);
|
QTC_ASSERT(editor, return);
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ private:
|
|||||||
ClangdClient *createClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir);
|
ClangdClient *createClient(ProjectExplorer::Project *project, const Utils::FilePath &jsonDbDir);
|
||||||
void claimNonProjectSources(ClangdClient *fallbackClient);
|
void claimNonProjectSources(ClangdClient *fallbackClient);
|
||||||
void watchForExternalChanges();
|
void watchForExternalChanges();
|
||||||
|
void watchForInternalChanges();
|
||||||
|
|
||||||
private:
|
|
||||||
UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
|
UiHeaderOnDiskManager m_uiHeaderOnDiskManager;
|
||||||
BackendCommunicator m_communicator;
|
BackendCommunicator m_communicator;
|
||||||
ClangCompletionAssistProvider m_completionAssistProvider;
|
ClangCompletionAssistProvider m_completionAssistProvider;
|
||||||
|
|||||||
Reference in New Issue
Block a user