forked from qt-creator/qt-creator
C++: Base parsing on editor document instead of widget
This mainly takes CppEditorSupport apart.
* Parsing is now invoked by CPPEditorDocument itself by listening to
QTextDocument::contentsChanged().
* Upon construction and destruction CPPEditorDocument creates and
deletes an EditorDocumentHandle for (un)registration in the model
manager. This handle provides everything to generate the working copy
and to access the editor document processor.
* A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that
controls parsing, semantic info recalculation and the semantic
highlighting for the document. This is more or less what is left from
CppEditorSupport and can be considered as the backend of a
CPPEditorDocument. CPPEditorDocument itself is quite small.
* BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor
derive from BaseEditorDocumentProcessor and implement the gaps.
* Since the semantic info calculation was bound to the widget, it
also calculated the local uses, which depend on the cursor
position. This calculation got moved into the extracted class
UseSeletionsUpdater in the cppeditor plugin, which is run once the
cursor position changes or the semantic info document is updated.
* Some more logic got extracted:
- SemanticInfoUpdater (logic was in CppEditorSupport)
- SemanticHighlighter (logic was in CppEditorSupport)
* The *Parser and *Processor classes can be easily accessed by the
static function get().
* CppHighlightingSupport is gone since it turned out to be useless.
* The editor dependency in CompletionAssistProviders is gone since we
actually only need the file path now.
Change-Id: I49d3a7bd138c5ed9620123e34480772535156508
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -30,11 +30,7 @@
|
||||
#include "clangutils.h"
|
||||
#include "cppcreatemarkers.h"
|
||||
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <cpptools/cppworkingcopy.h>
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -51,119 +47,52 @@ using namespace CppTools;
|
||||
|
||||
CreateMarkers *CreateMarkers::create(SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName,
|
||||
const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo)
|
||||
unsigned firstLine, unsigned lastLine)
|
||||
{
|
||||
if (semanticMarker.isNull())
|
||||
return 0;
|
||||
else
|
||||
return new CreateMarkers(semanticMarker, fileName, options, firstLine, lastLine, fastIndexer, pchInfo);
|
||||
return new CreateMarkers(semanticMarker, fileName, firstLine, lastLine);
|
||||
}
|
||||
|
||||
CreateMarkers::CreateMarkers(SemanticMarker::Ptr semanticMarker,
|
||||
const QString &fileName,
|
||||
const QStringList &options,
|
||||
unsigned firstLine, unsigned lastLine,
|
||||
FastIndexer *fastIndexer,
|
||||
const Internal::PchInfo::Ptr &pchInfo)
|
||||
unsigned firstLine, unsigned lastLine)
|
||||
: m_marker(semanticMarker)
|
||||
, m_pchInfo(pchInfo)
|
||||
, m_fileName(fileName)
|
||||
, m_options(options)
|
||||
, m_firstLine(firstLine)
|
||||
, m_lastLine(lastLine)
|
||||
, m_fastIndexer(fastIndexer)
|
||||
{
|
||||
Q_ASSERT(!semanticMarker.isNull());
|
||||
|
||||
m_flushRequested = false;
|
||||
m_flushLine = 0;
|
||||
|
||||
m_unsavedFiles = Utils::createUnsavedFiles(CppModelManagerInterface::instance()->workingCopy());
|
||||
}
|
||||
|
||||
CreateMarkers::~CreateMarkers()
|
||||
{ }
|
||||
|
||||
static QString commandLine(const QStringList &options, const QString &fileName)
|
||||
{
|
||||
const QStringList allOptions = QStringList(options)
|
||||
<< QLatin1String("-fsyntax-only") << fileName;
|
||||
QStringList allOptionsQuoted;
|
||||
foreach (const QString &option, allOptions)
|
||||
allOptionsQuoted.append(QLatin1Char('\'') + option + QLatin1Char('\''));
|
||||
return ::Utils::HostOsInfo::withExecutableSuffix(QLatin1String("clang"))
|
||||
+ QLatin1Char(' ') + allOptionsQuoted.join(QLatin1Char(' '));
|
||||
}
|
||||
|
||||
void CreateMarkers::run()
|
||||
{
|
||||
QMutexLocker lock(m_marker->mutex());
|
||||
if (isCanceled())
|
||||
return;
|
||||
|
||||
m_options += QLatin1String("-fspell-checking");
|
||||
|
||||
QTime t;
|
||||
if (DebugTiming) {
|
||||
qDebug() << "*** Highlighting from" << m_firstLine << "to" << m_lastLine << "of" << m_fileName;
|
||||
qDebug("***** Options (cmd line equivalent): %s",
|
||||
commandLine(m_options, m_fileName).toUtf8().constData());
|
||||
t.start();
|
||||
}
|
||||
|
||||
m_usages.clear();
|
||||
m_marker->setFileName(m_fileName);
|
||||
m_marker->setCompilationOptions(m_options);
|
||||
|
||||
m_marker->reparse(m_unsavedFiles);
|
||||
|
||||
if (DebugTiming)
|
||||
qDebug() << "*** Reparse for highlighting took" << t.elapsed() << "ms.";
|
||||
|
||||
m_pchInfo.clear();
|
||||
|
||||
typedef CPlusPlus::Document::DiagnosticMessage OtherDiagnostic;
|
||||
QList<OtherDiagnostic> msgs;
|
||||
foreach (const ClangCodeModel::Diagnostic &d, m_marker->diagnostics()) {
|
||||
if (DebugTiming)
|
||||
qDebug() << d.severityAsString() << d.location() << d.spelling();
|
||||
|
||||
if (d.location().fileName() != m_marker->fileName())
|
||||
continue;
|
||||
|
||||
// TODO: retrieve fix-its for this diagnostic
|
||||
|
||||
int level;
|
||||
switch (d.severity()) {
|
||||
case Diagnostic::Fatal: level = OtherDiagnostic::Fatal; break;
|
||||
case Diagnostic::Error: level = OtherDiagnostic::Error; break;
|
||||
case Diagnostic::Warning: level = OtherDiagnostic::Warning; break;
|
||||
default: continue;
|
||||
}
|
||||
msgs.append(OtherDiagnostic(level, d.location().fileName(), d.location().line(),
|
||||
d.location().column(), d.spelling(), d.length()));
|
||||
}
|
||||
if (isCanceled()) {
|
||||
reportFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
CppModelManagerInterface *mmi = CppModelManagerInterface::instance();
|
||||
static const QString key = QLatin1String("ClangCodeModel.Diagnostics");
|
||||
mmi->setExtraDiagnostics(m_marker->fileName(), key, msgs);
|
||||
#if CINDEX_VERSION_MINOR >= 21
|
||||
mmi->setIfdefedOutBlocks(m_marker->fileName(), m_marker->ifdefedOutBlocks());
|
||||
#endif
|
||||
|
||||
if (isCanceled()) {
|
||||
reportFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
QList<ClangCodeModel::SourceMarker> markers = m_marker->sourceMarkersInRange(m_firstLine, m_lastLine);
|
||||
const QList<ClangCodeModel::SourceMarker> markers
|
||||
= m_marker->sourceMarkersInRange(m_firstLine, m_lastLine);
|
||||
foreach (const ClangCodeModel::SourceMarker &m, markers)
|
||||
addUse(SourceMarker(m.location().line(), m.location().column(), m.length(), m.kind()));
|
||||
|
||||
@@ -179,12 +108,6 @@ void CreateMarkers::run()
|
||||
qDebug() << "*** Highlighting took" << t.elapsed() << "ms in total.";
|
||||
t.restart();
|
||||
}
|
||||
|
||||
if (m_fastIndexer)
|
||||
m_fastIndexer->indexNow(m_marker->unit());
|
||||
|
||||
if (DebugTiming)
|
||||
qDebug() << "*** Fast re-indexing took" << t.elapsed() << "ms in total.";
|
||||
}
|
||||
|
||||
void CreateMarkers::addUse(const SourceMarker &marker)
|
||||
|
||||
Reference in New Issue
Block a user