Commit 9f7a2194 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Fix infinite loop when scanning for exported C++ types.

Setting extra diagnostics would call updateDocument which would in turn
trigger another scan.

Change-Id: I3810a380cdf716a12767d94ff82dc30f8ae3954d
Reviewed-on: http://codereview.qt.nokia.com/3917Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent 7bc8dd18
......@@ -603,6 +603,22 @@ void Document::releaseSourceAndAST()
}
}
bool Document::DiagnosticMessage::operator==(const Document::DiagnosticMessage &other) const
{
return
_line == other._line &&
_column == other._column &&
_length == other._length &&
_level == other._level &&
_fileName == other._fileName &&
_text == other._text;
}
bool Document::DiagnosticMessage::operator!=(const Document::DiagnosticMessage &other) const
{
return !operator==(other);
}
Snapshot::Snapshot()
{
}
......
......@@ -177,6 +177,9 @@ public:
QString text() const
{ return _text; }
bool operator==(const DiagnosticMessage &other) const;
bool operator!=(const DiagnosticMessage &other) const;
private:
int _level;
QString _fileName;
......
......@@ -154,6 +154,7 @@ public:
Q_SIGNALS:
void documentUpdated(CPlusPlus::Document::Ptr doc);
void sourceFilesRefreshed(const QStringList &files);
void extraDiagnosticsUpdated(QString fileName);
public Q_SLOTS:
virtual void updateModifiedSourceFiles() = 0;
......
......@@ -694,6 +694,8 @@ CppModelManager::CppModelManager(QObject *parent)
// thread connections
connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)));
connect(this, SIGNAL(extraDiagnosticsUpdated(QString)),
this, SLOT(onExtraDiagnosticsUpdated(QString)));
// Listen for editor closed and opened events so that we can keep track of changing files
connect(m_core->editorManager(), SIGNAL(editorOpened(Core::IEditor *)),
......@@ -968,6 +970,22 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
if (outdated)
return;
updateEditor(doc);
}
void CppModelManager::onExtraDiagnosticsUpdated(const QString &fileName)
{
protectSnapshot.lock();
Document::Ptr doc = m_snapshot.document(fileName);
protectSnapshot.unlock();
if (doc)
updateEditor(doc);
}
void CppModelManager::updateEditor(Document::Ptr doc)
{
const QString fileName = doc->fileName();
QList<Core::IEditor *> openedEditors = m_core->editorManager()->openedEditors();
foreach (Core::IEditor *editor, openedEditors) {
if (editor->file()->fileName() == fileName) {
......@@ -1297,15 +1315,11 @@ void CppModelManager::setExtraDiagnostics(const QString &fileName, int kind,
{
{
QMutexLocker locker(&protectExtraDiagnostics);
if (m_extraDiagnostics[fileName][kind] == diagnostics)
return;
m_extraDiagnostics[fileName].insert(kind, diagnostics);
}
Document::Ptr doc;
{
QMutexLocker locker(&protectSnapshot);
doc = m_snapshot.document(fileName);
}
if (doc)
emit documentUpdated(doc);
emit extraDiagnosticsUpdated(fileName);
}
QList<Document::DiagnosticMessage> CppModelManager::extraDiagnostics(const QString &fileName, int kind) const
......
......@@ -150,6 +150,7 @@ public Q_SLOTS:
private Q_SLOTS:
// this should be executed in the GUI thread.
void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
void onExtraDiagnosticsUpdated(const QString &fileName);
void onAboutToRemoveProject(ProjectExplorer::Project *project);
void onAboutToUnloadSession();
void onProjectAdded(ProjectExplorer::Project *project);
......@@ -157,6 +158,8 @@ private Q_SLOTS:
void updateEditorSelections();
private:
void updateEditor(CPlusPlus::Document::Ptr doc);
WorkingCopy buildWorkingCopyList();
QStringList projectFiles()
......
Markdown is supported
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