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