Commit 6df66e88 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

CppTools: Do not hand over partly reloaded files to the code model



When a reloading operation was in progress, CppEditorSupport::contents()
could return a partly reloaded file to the code model leading to parse
errors and incomplete highlighting.

Fixed by checking if the file is currently being reloaded.

Task-number: QTCREATORBUG-9382

Change-Id: Iee97e10444763c0cbf481132afa4617c5cdbd15c
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 10ff6769
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h> #include <utils/runextensions.h>
#include <QList> #include <QList>
...@@ -113,6 +114,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor ...@@ -113,6 +114,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
, m_updateDocumentInterval(UpdateDocumentDefaultInterval) , m_updateDocumentInterval(UpdateDocumentDefaultInterval)
, m_revision(0) , m_revision(0)
, m_cachedContentsEditorRevision(-1) , m_cachedContentsEditorRevision(-1)
, m_fileIsBeingReloaded(false)
, m_initialized(false) , m_initialized(false)
, m_lastHighlightRevision(0) , m_lastHighlightRevision(0)
, m_highlightingSupport(modelManager->highlightingSupport(textEditor)) , m_highlightingSupport(modelManager->highlightingSupport(textEditor))
...@@ -142,6 +144,11 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor ...@@ -142,6 +144,11 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
connect(m_textEditor->document(), SIGNAL(mimeTypeChanged()), connect(m_textEditor->document(), SIGNAL(mimeTypeChanged()),
this, SLOT(onMimeTypeChanged())); this, SLOT(onMimeTypeChanged()));
connect(m_textEditor->document(), SIGNAL(aboutToReload()),
this, SLOT(onAboutToReload()));
connect(m_textEditor->document(), SIGNAL(reloadFinished(bool)),
this, SLOT(onReloadFinished()));
updateDocument(); updateDocument();
} }
...@@ -162,7 +169,7 @@ QString CppEditorSupport::fileName() const ...@@ -162,7 +169,7 @@ QString CppEditorSupport::fileName() const
QString CppEditorSupport::contents() const QString CppEditorSupport::contents() const
{ {
const int editorRev = editorRevision(); const int editorRev = editorRevision();
if (m_cachedContentsEditorRevision != editorRev) { if (m_cachedContentsEditorRevision != editorRev && !m_fileIsBeingReloaded) {
m_cachedContentsEditorRevision = editorRev; m_cachedContentsEditorRevision = editorRev;
m_cachedContents = m_textEditor->textDocument()->contents(); m_cachedContents = m_textEditor->textDocument()->contents();
} }
...@@ -233,9 +240,11 @@ void CppEditorSupport::updateDocumentNow() ...@@ -233,9 +240,11 @@ void CppEditorSupport::updateDocumentNow()
} else { } else {
m_updateDocumentTimer->stop(); m_updateDocumentTimer->stop();
if (m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo()) { if (m_fileIsBeingReloaded)
return;
if (m_highlightingSupport && !m_highlightingSupport->requiresSemanticInfo())
startHighlighting(); startHighlighting();
}
const QStringList sourceFiles(m_textEditor->document()->fileName()); const QStringList sourceFiles(m_textEditor->document()->fileName());
m_documentParser = m_modelManager->updateSourceFiles(sourceFiles); m_documentParser = m_modelManager->updateSourceFiles(sourceFiles);
...@@ -505,3 +514,16 @@ void CppEditorSupport::onMimeTypeChanged() ...@@ -505,3 +514,16 @@ void CppEditorSupport::onMimeTypeChanged()
updateDocumentNow(); updateDocumentNow();
} }
void CppEditorSupport::onAboutToReload()
{
QTC_CHECK(!m_fileIsBeingReloaded);
m_fileIsBeingReloaded = true;
}
void CppEditorSupport::onReloadFinished()
{
QTC_CHECK(m_fileIsBeingReloaded);
m_fileIsBeingReloaded = false;
updateDocument();
}
...@@ -121,6 +121,9 @@ signals: ...@@ -121,6 +121,9 @@ signals:
private slots: private slots:
void onMimeTypeChanged(); void onMimeTypeChanged();
void onAboutToReload();
void onReloadFinished();
void updateDocument(); void updateDocument();
void updateDocumentNow(); void updateDocumentNow();
...@@ -166,6 +169,7 @@ private: ...@@ -166,6 +169,7 @@ private:
// content caching // content caching
mutable QString m_cachedContents; mutable QString m_cachedContents;
mutable int m_cachedContentsEditorRevision; mutable int m_cachedContentsEditorRevision;
bool m_fileIsBeingReloaded;
QTimer *m_updateEditorTimer; QTimer *m_updateEditorTimer;
EditorUpdates m_editorUpdates; EditorUpdates m_editorUpdates;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment