CppEditor: Fix invalidating diagnostics on reload

Issue was:
 1. Open some small file without any includes but with diagnostics
 2. Switch to the shell and touch the file open in Qt Creator
 3. Switch back to Qt Creator and confirm reload
  --> Ops, inline diagnostic stays invalidated/gray

This is due to a race condition. The problematic sequence is:

  1. CppEditorDocument::scheduleProcessDocument()
       // OK, because contents changed
  2. ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool)
       // OK, because we listen on TextDocument::contentsChangedWithPosition.
       // Because of the fast reparse, new diagnostics are processed with
       // ClangEditorDocumentProcessor::updateCodeWarnings().
  3. CppEditorDocument::processDocument()
       // Timeout, invalidates the already up to date diagnostics

Avoid to trigger the process timer during a reload.

Change-Id: I712d6b2fd5524d5fe6866dbdbb8cbca05e4aef2c
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-07-06 12:04:19 +02:00
parent be3e12c8af
commit db88225b0e

View File

@@ -201,12 +201,17 @@ void CppEditorDocument::onAboutToReload()
{
QTC_CHECK(!m_fileIsBeingReloaded);
m_fileIsBeingReloaded = true;
processor()->invalidateDiagnostics();
}
void CppEditorDocument::onReloadFinished()
{
QTC_CHECK(m_fileIsBeingReloaded);
m_fileIsBeingReloaded = false;
m_processorRevision = document()->revision();
processDocument();
}
void CppEditorDocument::reparseWithPreferredParseContext(const QString &parseContextId)
@@ -250,6 +255,9 @@ void CppEditorDocument::onFilePathChanged(const Utils::FileName &oldPath,
void CppEditorDocument::scheduleProcessDocument()
{
if (m_fileIsBeingReloaded)
return;
m_processorRevision = document()->revision();
m_processorTimer.start();
processor()->editorDocumentTimerRestarted();