forked from qt-creator/qt-creator
CppTools: restore C++ diagnostics messages.
The messages were computed, but not added to the document. Change-Id: Ibeea802cf9f291ad14b2fe2e9d2a285c927a4449 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
a645f78cd6
commit
7e544073c0
@@ -50,15 +50,14 @@ enum { debug = 0 };
|
||||
|
||||
namespace {
|
||||
|
||||
QFuture<TextEditor::HighlightingResult> runHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
QTextDocument *textDocument)
|
||||
CppTools::CheckSymbols * createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
const CPlusPlus::Snapshot &snapshot,
|
||||
QTextDocument *textDocument)
|
||||
{
|
||||
QFuture<TextEditor::HighlightingResult> failed;
|
||||
QTC_ASSERT(doc, return failed);
|
||||
QTC_ASSERT(doc->translationUnit(), return failed);
|
||||
QTC_ASSERT(doc->translationUnit()->ast(), return failed);
|
||||
QTC_ASSERT(textDocument, return failed);
|
||||
QTC_ASSERT(doc, return 0);
|
||||
QTC_ASSERT(doc->translationUnit(), return 0);
|
||||
QTC_ASSERT(doc->translationUnit()->ast(), return 0);
|
||||
QTC_ASSERT(textDocument, return 0);
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace CppTools;
|
||||
@@ -106,7 +105,7 @@ QFuture<TextEditor::HighlightingResult> runHighlighter(const CPlusPlus::Document
|
||||
}
|
||||
|
||||
LookupContext context(doc, snapshot);
|
||||
return CheckSymbols::go(doc, context, macroUses);
|
||||
return CheckSymbols::create(doc, context, macroUses);
|
||||
}
|
||||
|
||||
QList<TextEditor::BlockRange> toTextEditorBlocks(
|
||||
@@ -128,6 +127,7 @@ BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(
|
||||
bool enableSemanticHighlighter)
|
||||
: BaseEditorDocumentProcessor(document)
|
||||
, m_parser(document->filePath())
|
||||
, m_codeWarningsUpdated(false)
|
||||
, m_semanticHighlighter(enableSemanticHighlighter
|
||||
? new CppTools::SemanticHighlighter(document)
|
||||
: 0)
|
||||
@@ -141,8 +141,12 @@ BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(
|
||||
m_semanticHighlighter->setHighlightingRunner(
|
||||
[this]() -> QFuture<TextEditor::HighlightingResult> {
|
||||
const SemanticInfo semanticInfo = m_semanticInfoUpdater.semanticInfo();
|
||||
return runHighlighter(semanticInfo.doc, semanticInfo.snapshot,
|
||||
baseTextDocument()->document());
|
||||
CheckSymbols *checkSymbols = createHighlighter(semanticInfo.doc, semanticInfo.snapshot,
|
||||
baseTextDocument()->document());
|
||||
QTC_ASSERT(checkSymbols, return QFuture<TextEditor::HighlightingResult>());
|
||||
connect(checkSymbols, &CheckSymbols::codeWarningsUpdated,
|
||||
this, &BuiltinEditorDocumentProcessor::onCodeWarningsUpdated);
|
||||
return checkSymbols->start();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -206,9 +210,9 @@ void BuiltinEditorDocumentProcessor::onParserFinished(CPlusPlus::Document::Ptr d
|
||||
const auto ifdefoutBlocks = toTextEditorBlocks(document->skippedBlocks());
|
||||
emit ifdefedOutBlocksUpdated(revision(), ifdefoutBlocks);
|
||||
|
||||
// Emit code warnings
|
||||
auto codeWarnings = toTextEditorSelections(document->diagnosticMessages(), textDocument());
|
||||
emit codeWarningsUpdated(revision(), codeWarnings);
|
||||
// Store parser warnings
|
||||
m_codeWarnings = toTextEditorSelections(document->diagnosticMessages(), textDocument());
|
||||
m_codeWarningsUpdated = false;
|
||||
|
||||
emit cppDocumentUpdated(document);
|
||||
|
||||
@@ -231,6 +235,27 @@ void BuiltinEditorDocumentProcessor::onSemanticInfoUpdated(const SemanticInfo se
|
||||
m_semanticHighlighter->run();
|
||||
}
|
||||
|
||||
void BuiltinEditorDocumentProcessor::onCodeWarningsUpdated(
|
||||
CPlusPlus::Document::Ptr document,
|
||||
const QList<CPlusPlus::Document::DiagnosticMessage> &codeWarnings)
|
||||
{
|
||||
if (document.isNull())
|
||||
return;
|
||||
|
||||
if (document->fileName() != filePath())
|
||||
return; // some other document got updated
|
||||
|
||||
if (document->editorRevision() != revision())
|
||||
return; // outdated content, wait for a new document to be parsed
|
||||
|
||||
if (m_codeWarningsUpdated)
|
||||
return; // code warnings already updated
|
||||
|
||||
m_codeWarnings += toTextEditorSelections(codeWarnings, textDocument());
|
||||
m_codeWarningsUpdated = true;
|
||||
emit codeWarningsUpdated(revision(), m_codeWarnings);
|
||||
}
|
||||
|
||||
SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bool force) const
|
||||
{
|
||||
const WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy();
|
||||
|
@@ -60,6 +60,8 @@ public:
|
||||
private:
|
||||
void onParserFinished(CPlusPlus::Document::Ptr document, CPlusPlus::Snapshot snapshot);
|
||||
void onSemanticInfoUpdated(const CppTools::SemanticInfo semanticInfo);
|
||||
void onCodeWarningsUpdated(CPlusPlus::Document::Ptr document,
|
||||
const QList<CPlusPlus::Document::DiagnosticMessage> &codeWarnings);
|
||||
|
||||
SemanticInfo::Source createSemanticInfoSource(bool force) const;
|
||||
|
||||
@@ -68,6 +70,8 @@ private:
|
||||
QFuture<void> m_parserFuture;
|
||||
|
||||
CPlusPlus::Snapshot m_documentSnapshot;
|
||||
QList<QTextEdit::ExtraSelection> m_codeWarnings;
|
||||
bool m_codeWarningsUpdated;
|
||||
|
||||
SemanticInfoUpdater m_semanticInfoUpdater;
|
||||
QScopedPointer<SemanticHighlighter> m_semanticHighlighter;
|
||||
|
@@ -305,6 +305,16 @@ CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &co
|
||||
return (new CheckSymbols(doc, context, macroUses))->start();
|
||||
}
|
||||
|
||||
CheckSymbols * CheckSymbols::create(Document::Ptr doc, const LookupContext &context,
|
||||
const QList<CheckSymbols::Result> ¯oUses)
|
||||
{
|
||||
QTC_ASSERT(doc, return NULL);
|
||||
QTC_ASSERT(doc->translationUnit(), return NULL);
|
||||
QTC_ASSERT(doc->translationUnit()->ast(), return NULL);
|
||||
|
||||
return new CheckSymbols(doc, context, macroUses);
|
||||
}
|
||||
|
||||
CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Result> ¯oUses)
|
||||
: ASTVisitor(doc->translationUnit()), _doc(doc), _context(context)
|
||||
, _lineOfLastUsage(0), _macroUses(macroUses)
|
||||
@@ -335,10 +345,6 @@ void CheckSymbols::run()
|
||||
_potentialStatics = collectTypes.statics();
|
||||
|
||||
Utils::sort(_macroUses, sortByLinePredicate);
|
||||
// TODO: Handle concurrent (write) access of diagnostic messages and ensure
|
||||
// propagation to the editor widget
|
||||
// _doc->clearDiagnosticMessages();
|
||||
|
||||
if (!isCanceled()) {
|
||||
if (_doc->translationUnit()) {
|
||||
accept(_doc->translationUnit()->ast());
|
||||
@@ -347,15 +353,15 @@ void CheckSymbols::run()
|
||||
}
|
||||
}
|
||||
|
||||
emit codeWarningsUpdated(_doc, _diagMsgs);
|
||||
|
||||
reportFinished();
|
||||
}
|
||||
|
||||
bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length)
|
||||
{
|
||||
Document::DiagnosticMessage m(Document::DiagnosticMessage::Warning, _fileName, line, column, text, length);
|
||||
// TODO: Handle concurrent (write) access of diagnostic messages and ensure
|
||||
// propagation to the editor widget
|
||||
// _doc->addDiagnosticMessage(m);
|
||||
_diagMsgs.append(m);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -44,10 +44,12 @@
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT CheckSymbols:
|
||||
public QObject,
|
||||
protected CPlusPlus::ASTVisitor,
|
||||
public QRunnable,
|
||||
public QFutureInterface<TextEditor::HighlightingResult>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
virtual ~CheckSymbols();
|
||||
|
||||
@@ -70,6 +72,9 @@ public:
|
||||
static Future go(CPlusPlus::Document::Ptr doc,
|
||||
const CPlusPlus::LookupContext &context,
|
||||
const QList<Result> ¯oUses);
|
||||
static CheckSymbols * create(CPlusPlus::Document::Ptr doc,
|
||||
const CPlusPlus::LookupContext &context,
|
||||
const QList<Result> ¯oUses);
|
||||
|
||||
static QMap<int, QVector<Result> > chunks(const QFuture<Result> &future, int from, int to)
|
||||
{
|
||||
@@ -87,6 +92,10 @@ public:
|
||||
return chunks;
|
||||
}
|
||||
|
||||
signals:
|
||||
void codeWarningsUpdated(CPlusPlus::Document::Ptr document,
|
||||
const QList<CPlusPlus::Document::DiagnosticMessage> selections);
|
||||
|
||||
protected:
|
||||
using ASTVisitor::visit;
|
||||
using ASTVisitor::endVisit;
|
||||
@@ -182,6 +191,7 @@ private:
|
||||
QSet<QByteArray> _potentialStatics;
|
||||
QList<CPlusPlus::AST *> _astStack;
|
||||
QVector<Result> _usages;
|
||||
QList<CPlusPlus::Document::DiagnosticMessage> _diagMsgs;
|
||||
int _chunkSize;
|
||||
unsigned _lineOfLastUsage;
|
||||
QList<Result> _macroUses;
|
||||
|
@@ -307,6 +307,8 @@ CppModelManager::CppModelManager(QObject *parent)
|
||||
this, SLOT(onCoreAboutToClose()));
|
||||
|
||||
qRegisterMetaType<CPlusPlus::Document::Ptr>("CPlusPlus::Document::Ptr");
|
||||
qRegisterMetaType<QList<CPlusPlus::Document::DiagnosticMessage>>(
|
||||
"QList<CPlusPlus::Document::DiagnosticMessage>");
|
||||
|
||||
d->m_modelManagerSupportFallback.reset(new ModelManagerSupportInternal);
|
||||
CppToolsPlugin::instance()->codeModelSettings()->setDefaultId(
|
||||
|
Reference in New Issue
Block a user