forked from qt-creator/qt-creator
CppTools: Provide the editor snapshot for SemanticInfoUpdater
...so that SemanticInfoUpdater does not depend anymore on the EditorDocumentParser. Accessing the snapshot was a blocking operation that delayed the semantic info update longer than actually needed. Change-Id: I348d22ef83ab310d4319b2e8b9678fe90ee24d6a Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -446,7 +446,9 @@ unsigned CppEditorWidget::documentRevision() const
|
|||||||
|
|
||||||
bool CppEditorWidget::isSemanticInfoValidExceptLocalUses() const
|
bool CppEditorWidget::isSemanticInfoValidExceptLocalUses() const
|
||||||
{
|
{
|
||||||
return d->m_lastSemanticInfo.doc && d->m_lastSemanticInfo.revision == documentRevision();
|
return d->m_lastSemanticInfo.doc
|
||||||
|
&& d->m_lastSemanticInfo.revision == documentRevision()
|
||||||
|
&& !d->m_lastSemanticInfo.snapshot.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppEditorWidget::isSemanticInfoValid() const
|
bool CppEditorWidget::isSemanticInfoValid() const
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
#include "cppeditordocument.h"
|
#include "cppeditordocument.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <cpptools/baseeditordocumentprocessor.h>
|
|
||||||
#include <cpptools/cppsemanticinfo.h>
|
#include <cpptools/cppsemanticinfo.h>
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
|
|
||||||
@@ -88,9 +87,6 @@ bool TestCase::openCppEditor(const QString &fileName, CppEditor **editor, CppEdi
|
|||||||
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(
|
CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(
|
||||||
CppEditorWidget *editorWidget)
|
CppEditorWidget *editorWidget)
|
||||||
{
|
{
|
||||||
const QString filePath = editorWidget->textDocument()->filePath();
|
|
||||||
auto processor = CppTools::BaseEditorDocumentProcessor::get(filePath);
|
|
||||||
processor->semanticRehighlight(false);
|
|
||||||
while (!editorWidget->isSemanticInfoValid())
|
while (!editorWidget->isSemanticInfoValid())
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
return editorWidget->semanticInfo().doc;
|
return editorWidget->semanticInfo().doc;
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath
|
|||||||
, m_forceSnapshotInvalidation(false)
|
, m_forceSnapshotInvalidation(false)
|
||||||
, m_releaseSourceAndAST(true)
|
, m_releaseSourceAndAST(true)
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
|
void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
|
||||||
@@ -187,6 +188,8 @@ void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
|
|||||||
}
|
}
|
||||||
m_snapshot = newSnapshot;
|
m_snapshot = newSnapshot;
|
||||||
m_deps.build(m_snapshot);
|
m_deps.build(m_snapshot);
|
||||||
|
|
||||||
|
emit finished(document(), m_snapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ public:
|
|||||||
|
|
||||||
void setReleaseSourceAndAST(bool onoff);
|
void setReleaseSourceAndAST(bool onoff);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void finished(CPlusPlus::Document::Ptr document, CPlusPlus::Snapshot snapshot);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BuiltinEditorDocumentParser *get(const QString &filePath);
|
static BuiltinEditorDocumentParser *get(const QString &filePath);
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,6 @@ BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(
|
|||||||
bool enableSemanticHighlighter)
|
bool enableSemanticHighlighter)
|
||||||
: BaseEditorDocumentProcessor(document)
|
: BaseEditorDocumentProcessor(document)
|
||||||
, m_parser(new BuiltinEditorDocumentParser(document->filePath()))
|
, m_parser(new BuiltinEditorDocumentParser(document->filePath()))
|
||||||
, m_semanticInfoUpdater(m_parser.data())
|
|
||||||
, m_semanticHighlighter(enableSemanticHighlighter
|
, m_semanticHighlighter(enableSemanticHighlighter
|
||||||
? new CppTools::SemanticHighlighter(document)
|
? new CppTools::SemanticHighlighter(document)
|
||||||
: 0)
|
: 0)
|
||||||
@@ -151,8 +150,8 @@ BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(cmm(), &CppModelManager::documentUpdated,
|
connect(m_parser.data(), &BuiltinEditorDocumentParser::finished,
|
||||||
this, &BuiltinEditorDocumentProcessor::onDocumentUpdated);
|
this, &BuiltinEditorDocumentProcessor::onParserFinished);
|
||||||
connect(&m_semanticInfoUpdater, &SemanticInfoUpdater::updated,
|
connect(&m_semanticInfoUpdater, &SemanticInfoUpdater::updated,
|
||||||
this, &BuiltinEditorDocumentProcessor::onSemanticInfoUpdated);
|
this, &BuiltinEditorDocumentProcessor::onSemanticInfoUpdated);
|
||||||
}
|
}
|
||||||
@@ -197,7 +196,8 @@ BuiltinEditorDocumentProcessor *BuiltinEditorDocumentProcessor::get(const QStrin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEditorDocumentProcessor::onDocumentUpdated(CPlusPlus::Document::Ptr document)
|
void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr document,
|
||||||
|
CPlusPlus::Snapshot snapshot)
|
||||||
{
|
{
|
||||||
if (document.isNull())
|
if (document.isNull())
|
||||||
return;
|
return;
|
||||||
@@ -223,7 +223,9 @@ void BuiltinEditorDocumentProcessor::onDocumentUpdated(CPlusPlus::Document::Ptr
|
|||||||
|
|
||||||
emit cppDocumentUpdated(document);
|
emit cppDocumentUpdated(document);
|
||||||
|
|
||||||
|
m_documentSnapshot = snapshot;
|
||||||
const auto source = createSemanticInfoSource(false);
|
const auto source = createSemanticInfoSource(false);
|
||||||
|
QTC_CHECK(source.snapshot.contains(document->fileName()));
|
||||||
m_semanticInfoUpdater.updateDetached(source);
|
m_semanticInfoUpdater.updateDetached(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,6 +249,7 @@ SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bo
|
|||||||
return SemanticInfo::Source(path,
|
return SemanticInfo::Source(path,
|
||||||
workingCopy.source(path),
|
workingCopy.source(path),
|
||||||
workingCopy.revision(path),
|
workingCopy.revision(path),
|
||||||
|
m_documentSnapshot,
|
||||||
force);
|
force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
static BuiltinEditorDocumentProcessor *get(const QString &filePath);
|
static BuiltinEditorDocumentProcessor *get(const QString &filePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDocumentUpdated(CPlusPlus::Document::Ptr document);
|
void onParserFinished(CPlusPlus::Document::Ptr document, CPlusPlus::Snapshot snapshot);
|
||||||
void onSemanticInfoUpdated(const CppTools::SemanticInfo semanticInfo);
|
void onSemanticInfoUpdated(const CppTools::SemanticInfo semanticInfo);
|
||||||
|
|
||||||
SemanticInfo::Source createSemanticInfoSource(bool force) const;
|
SemanticInfo::Source createSemanticInfoSource(bool force) const;
|
||||||
@@ -70,6 +70,8 @@ private:
|
|||||||
QScopedPointer<BuiltinEditorDocumentParser> m_parser;
|
QScopedPointer<BuiltinEditorDocumentParser> m_parser;
|
||||||
QFuture<void> m_parserFuture;
|
QFuture<void> m_parserFuture;
|
||||||
|
|
||||||
|
CPlusPlus::Snapshot m_documentSnapshot;
|
||||||
|
|
||||||
SemanticInfoUpdater m_semanticInfoUpdater;
|
SemanticInfoUpdater m_semanticInfoUpdater;
|
||||||
QScopedPointer<SemanticHighlighter> m_semanticHighlighter;
|
QScopedPointer<SemanticHighlighter> m_semanticHighlighter;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
const QString fileName;
|
const QString fileName;
|
||||||
const QByteArray code;
|
const QByteArray code;
|
||||||
const unsigned revision;
|
const unsigned revision;
|
||||||
|
CPlusPlus::Snapshot snapshot;
|
||||||
const bool force;
|
const bool force;
|
||||||
|
|
||||||
Source() : revision(0), force(false) {}
|
Source() : revision(0), force(false) {}
|
||||||
@@ -55,10 +56,12 @@ public:
|
|||||||
Source(const QString &fileName,
|
Source(const QString &fileName,
|
||||||
const QByteArray &code,
|
const QByteArray &code,
|
||||||
unsigned revision,
|
unsigned revision,
|
||||||
|
const CPlusPlus::Snapshot &snapshot,
|
||||||
bool force)
|
bool force)
|
||||||
: fileName(fileName)
|
: fileName(fileName)
|
||||||
, code(code)
|
, code(code)
|
||||||
, revision(revision)
|
, revision(revision)
|
||||||
|
, snapshot(snapshot)
|
||||||
, force(force)
|
, force(force)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,10 +27,10 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "builtineditordocumentparser.h"
|
|
||||||
#include "cpplocalsymbols.h"
|
|
||||||
#include "cppsemanticinfoupdater.h"
|
#include "cppsemanticinfoupdater.h"
|
||||||
|
|
||||||
|
#include "cpplocalsymbols.h"
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcoverride.h>
|
#include <utils/qtcoverride.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q, BuiltinEditorDocumentParser *m_parser);
|
SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q);
|
||||||
~SemanticInfoUpdaterPrivate();
|
~SemanticInfoUpdaterPrivate();
|
||||||
|
|
||||||
SemanticInfo semanticInfo() const;
|
SemanticInfo semanticInfo() const;
|
||||||
@@ -79,13 +79,10 @@ public:
|
|||||||
mutable QMutex m_lock;
|
mutable QMutex m_lock;
|
||||||
SemanticInfo m_semanticInfo;
|
SemanticInfo m_semanticInfo;
|
||||||
QFuture<void> m_future;
|
QFuture<void> m_future;
|
||||||
BuiltinEditorDocumentParser *m_parser;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SemanticInfoUpdaterPrivate::SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q,
|
SemanticInfoUpdaterPrivate::SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q)
|
||||||
BuiltinEditorDocumentParser *parser)
|
|
||||||
: q(q)
|
: q(q)
|
||||||
, m_parser(parser)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,10 +120,7 @@ SemanticInfo SemanticInfoUpdaterPrivate::update(const SemanticInfo::Source &sour
|
|||||||
|
|
||||||
SemanticInfo newSemanticInfo;
|
SemanticInfo newSemanticInfo;
|
||||||
newSemanticInfo.revision = source.revision;
|
newSemanticInfo.revision = source.revision;
|
||||||
|
newSemanticInfo.snapshot = source.snapshot;
|
||||||
QTC_ASSERT(m_parser, return newSemanticInfo);
|
|
||||||
newSemanticInfo.snapshot = m_parser->snapshot();
|
|
||||||
QTC_ASSERT(newSemanticInfo.snapshot.contains(source.fileName), return newSemanticInfo);
|
|
||||||
|
|
||||||
Document::Ptr doc = newSemanticInfo.snapshot.preprocessedDocument(source.code, source.fileName);
|
Document::Ptr doc = newSemanticInfo.snapshot.preprocessedDocument(source.code, source.fileName);
|
||||||
if (processor)
|
if (processor)
|
||||||
@@ -154,11 +148,12 @@ bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::So
|
|||||||
&& currentSemanticInfo.revision == source.revision
|
&& currentSemanticInfo.revision == source.revision
|
||||||
&& currentSemanticInfo.doc
|
&& currentSemanticInfo.doc
|
||||||
&& currentSemanticInfo.doc->translationUnit()->ast()
|
&& currentSemanticInfo.doc->translationUnit()->ast()
|
||||||
&& currentSemanticInfo.doc->fileName() == source.fileName) {
|
&& currentSemanticInfo.doc->fileName() == source.fileName
|
||||||
|
&& !currentSemanticInfo.snapshot.isEmpty()) {
|
||||||
SemanticInfo newSemanticInfo;
|
SemanticInfo newSemanticInfo;
|
||||||
newSemanticInfo.revision = source.revision;
|
newSemanticInfo.revision = source.revision;
|
||||||
|
newSemanticInfo.snapshot = source.snapshot;
|
||||||
newSemanticInfo.doc = currentSemanticInfo.doc;
|
newSemanticInfo.doc = currentSemanticInfo.doc;
|
||||||
newSemanticInfo.snapshot = currentSemanticInfo.snapshot; // ### TODO: use the new snapshot.
|
|
||||||
setSemanticInfo(newSemanticInfo, emitSignalWhenFinished);
|
setSemanticInfo(newSemanticInfo, emitSignalWhenFinished);
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SemanticInfoUpdater: re-using current semantic info - source.revision"
|
qDebug() << "SemanticInfoUpdater: re-using current semantic info - source.revision"
|
||||||
@@ -176,8 +171,8 @@ void SemanticInfoUpdaterPrivate::update_helper(QFutureInterface<void> &future,
|
|||||||
update(source, true, &processor);
|
update(source, true, &processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticInfoUpdater::SemanticInfoUpdater(BuiltinEditorDocumentParser *parser)
|
SemanticInfoUpdater::SemanticInfoUpdater()
|
||||||
: d(new SemanticInfoUpdaterPrivate(this, parser))
|
: d(new SemanticInfoUpdaterPrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
class BuiltinEditorDocumentParser;
|
|
||||||
class SemanticInfoUpdaterPrivate;
|
class SemanticInfoUpdaterPrivate;
|
||||||
|
|
||||||
class SemanticInfoUpdater : public QObject
|
class SemanticInfoUpdater : public QObject
|
||||||
@@ -46,7 +45,7 @@ class SemanticInfoUpdater : public QObject
|
|||||||
Q_DISABLE_COPY(SemanticInfoUpdater)
|
Q_DISABLE_COPY(SemanticInfoUpdater)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SemanticInfoUpdater(BuiltinEditorDocumentParser *parser);
|
explicit SemanticInfoUpdater();
|
||||||
~SemanticInfoUpdater();
|
~SemanticInfoUpdater();
|
||||||
|
|
||||||
SemanticInfo semanticInfo() const;
|
SemanticInfo semanticInfo() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user