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:
Nikolai Kosjar
2014-08-19 15:59:29 +02:00
parent 2fa15f221f
commit 89bd4ee3c4
71 changed files with 2827 additions and 1139 deletions

View File

@@ -29,6 +29,8 @@
#include "baseeditordocumentparser.h"
#include "editordocumenthandle.h"
namespace CppTools {
/*!
@@ -101,6 +103,16 @@ void BaseEditorDocumentParser::setEditorDefines(const QByteArray &editorDefines)
}
}
BaseEditorDocumentParser *BaseEditorDocumentParser::get(const QString &filePath)
{
CppModelManagerInterface *cmmi = CppModelManagerInterface::instance();
if (EditorDocumentHandle *editorDocument = cmmi->editorDocument(filePath)) {
if (BaseEditorDocumentProcessor *processor = editorDocument->processor())
return processor->parser();
}
return 0;
}
void BaseEditorDocumentParser::updateProjectPart()
{
if (m_manuallySetProjectPart) {

View File

@@ -33,10 +33,13 @@
#include "cppmodelmanagerinterface.h"
#include "cpptools_global.h"
#include <QObject>
namespace CppTools {
class CPPTOOLS_EXPORT BaseEditorDocumentParser
class CPPTOOLS_EXPORT BaseEditorDocumentParser : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(BaseEditorDocumentParser)
BaseEditorDocumentParser();
@@ -57,6 +60,9 @@ public:
QByteArray editorDefines() const;
void setEditorDefines(const QByteArray &editorDefines);
public:
static BaseEditorDocumentParser *get(const QString &filePath);
protected:
void updateProjectPart();

View File

@@ -0,0 +1,135 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "baseeditordocumentprocessor.h"
#include "cppworkingcopy.h"
#include "editordocumenthandle.h"
#include <utils/qtcassert.h>
#include <QTextBlock>
namespace CppTools {
/*!
\class CppTools::BaseEditorDocumentProcessor
\brief The BaseEditorDocumentProcessor class controls and executes all
document relevant actions (reparsing, semantic highlighting, additional
semantic calculations) after a text document has changed.
*/
BaseEditorDocumentProcessor::BaseEditorDocumentProcessor(
TextEditor::BaseTextDocument *document)
: m_baseTextDocument(document)
{
QTC_CHECK(document);
}
BaseEditorDocumentProcessor::~BaseEditorDocumentProcessor()
{
}
TextEditor::BaseTextDocument *BaseEditorDocumentProcessor::baseTextDocument() const
{
return m_baseTextDocument;
}
BaseEditorDocumentProcessor *BaseEditorDocumentProcessor::get(const QString &filePath)
{
CppModelManagerInterface *cmmi = CppModelManagerInterface::instance();
if (EditorDocumentHandle *editorDocument = cmmi->editorDocument(filePath))
return editorDocument->processor();
return 0;
}
QList<QTextEdit::ExtraSelection> BaseEditorDocumentProcessor::toTextEditorSelections(
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics,
QTextDocument *textDocument)
{
// Format for errors
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
errorFormat.setUnderlineColor(Qt::red);
// Format for warnings
QTextCharFormat warningFormat;
warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
warningFormat.setUnderlineColor(Qt::darkYellow);
QList<QTextEdit::ExtraSelection> result;
foreach (const CPlusPlus::Document::DiagnosticMessage &m, diagnostics) {
QTextEdit::ExtraSelection sel;
if (m.isWarning())
sel.format = warningFormat;
else
sel.format = errorFormat;
QTextCursor c(textDocument->findBlockByNumber(m.line() - 1));
const QString text = c.block().text();
if (m.length() > 0 && m.column() + m.length() < (unsigned)text.size()) {
int column = m.column() > 0 ? m.column() - 1 : 0;
c.setPosition(c.position() + column);
c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, m.length());
} else {
for (int i = 0; i < text.size(); ++i) {
if (!text.at(i).isSpace()) {
c.setPosition(c.position() + i);
break;
}
}
c.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
sel.cursor = c;
sel.format.setToolTip(m.text());
result.append(sel);
}
return result;
}
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
BaseEditorDocumentParser *parser,
WorkingCopy workingCopy)
{
future.setProgressRange(0, 1);
if (future.isCanceled()) {
future.setProgressValue(1);
return;
}
parser->update(workingCopy);
CppModelManagerInterface::instance()
->finishedRefreshingSourceFiles(QStringList(parser->filePath()));
future.setProgressValue(1);
}
} // namespace CppTools

View File

@@ -0,0 +1,99 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef BASEEDITORDOCUMENTPROCESSOR_H
#define BASEEDITORDOCUMENTPROCESSOR_H
#include "baseeditordocumentparser.h"
#include "cppsemanticinfo.h"
#include "cpptools_global.h"
#include <texteditor/basetexteditor.h>
#include <cplusplus/CppDocument.h>
#include <QTextEdit>
namespace CppTools {
class CPPTOOLS_EXPORT BaseEditorDocumentProcessor : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(BaseEditorDocumentProcessor)
BaseEditorDocumentProcessor();
public:
BaseEditorDocumentProcessor(TextEditor::BaseTextDocument *document);
virtual ~BaseEditorDocumentProcessor();
TextEditor::BaseTextDocument *baseTextDocument() const;
// Function interface to implement
virtual void run() = 0;
virtual void semanticRehighlight(bool force) = 0;
virtual CppTools::SemanticInfo recalculateSemanticInfo() = 0;
virtual BaseEditorDocumentParser *parser() = 0;
virtual bool isParserRunning() const = 0;
public:
static BaseEditorDocumentProcessor *get(const QString &filePath);
signals:
// Signal interface to implement
void codeWarningsUpdated(unsigned revision,
const QList<QTextEdit::ExtraSelection> selections);
void ifdefedOutBlocksUpdated(unsigned revision,
const QList<TextEditor::BlockRange> ifdefedOutBlocks);
void cppDocumentUpdated(const CPlusPlus::Document::Ptr document); // TODO: Remove me
void semanticInfoUpdated(const CppTools::SemanticInfo semanticInfo); // TODO: Remove me
protected:
static QList<QTextEdit::ExtraSelection> toTextEditorSelections(
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics,
QTextDocument *textDocument);
static void runParser(QFutureInterface<void> &future,
CppTools::BaseEditorDocumentParser *parser,
CppTools::WorkingCopy workingCopy);
// Convenience
QString filePath() const { return m_baseTextDocument->filePath(); }
unsigned revision() const { return static_cast<unsigned>(textDocument()->revision()); }
QTextDocument *textDocument() const { return m_baseTextDocument->document(); }
private:
TextEditor::BaseTextDocument *m_baseTextDocument;
};
} // namespace CppTools
#endif // BASEEDITORDOCUMENTPROCESSOR_H

View File

@@ -29,6 +29,7 @@
#include "builtineditordocumentparser.h"
#include "cppsourceprocessor.h"
#include "editordocumenthandle.h"
#include <utils/qtcassert.h>
@@ -221,8 +222,15 @@ void BuiltinEditorDocumentParser::setReleaseSourceAndAST(bool onoff)
m_releaseSourceAndAST = onoff;
}
BuiltinEditorDocumentParser *BuiltinEditorDocumentParser::get(const QString &filePath)
{
if (BaseEditorDocumentParser *b = BaseEditorDocumentParser::get(filePath))
return qobject_cast<BuiltinEditorDocumentParser *>(b);
return 0;
}
void BuiltinEditorDocumentParser::addFileAndDependencies(QSet<QString> *toRemove,
const QString &fileName) const
const QString &fileName) const
{
toRemove->insert(fileName);
if (fileName != filePath()) {
@@ -230,4 +238,3 @@ void BuiltinEditorDocumentParser::addFileAndDependencies(QSet<QString> *toRemove
toRemove->unite(QSet<QString>::fromList(deps));
}
}

View File

@@ -45,8 +45,7 @@ namespace CppTools {
class CPPTOOLS_EXPORT BuiltinEditorDocumentParser : public BaseEditorDocumentParser
{
public:
typedef QSharedPointer<BuiltinEditorDocumentParser> Ptr;
Q_OBJECT
public:
BuiltinEditorDocumentParser(const QString &filePath);
@@ -60,6 +59,9 @@ public:
void setReleaseSourceAndAST(bool onoff);
public:
static BuiltinEditorDocumentParser *get(const QString &filePath);
private:
void addFileAndDependencies(QSet<QString> *toRemove, const QString &fileName) const;

View File

@@ -0,0 +1,253 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "builtineditordocumentprocessor.h"
#include "cppchecksymbols.h"
#include "cppcodemodelsettings.h"
#include "cppmodelmanager.h"
#include "cpptoolsplugin.h"
#include "cpptoolsreuse.h"
#include "cppworkingcopy.h"
#include <texteditor/basetexteditor.h>
#include <texteditor/convenience.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/SimpleLexer.h>
#include <utils/QtConcurrentTools>
#include <utils/qtcassert.h>
enum { debug = 0 };
namespace {
CppTools::Internal::CppModelManager *cmm()
{
return CppTools::Internal::CppModelManager::instance();
}
QFuture<TextEditor::HighlightingResult> runHighlighter(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);
using namespace CPlusPlus;
using namespace CppTools;
typedef TextEditor::HighlightingResult Result;
QList<Result> macroUses;
using TextEditor::Convenience::convertPosition;
// Get macro definitions
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
int line, column;
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, macro.nameToQString().size(), SemanticHighlighter::MacroUse);
macroUses.append(use);
}
// Get macro uses
foreach (const Document::MacroUse &macro, doc->macroUses()) {
const QString name = macro.macro().nameToQString();
//Filter out QtKeywords
if (isQtKeyword(QStringRef(&name)))
continue;
// Filter out C++ keywords
// FIXME: Check default values or get from document.
LanguageFeatures features;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const QList<Token> tokens = tokenize(name);
if (tokens.length() && (tokens.at(0).isKeyword() || tokens.at(0).isObjCAtKeyword()))
continue;
int line, column;
convertPosition(textDocument, macro.utf16charsBegin(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, name.size(), SemanticHighlighter::MacroUse);
macroUses.append(use);
}
LookupContext context(doc, snapshot);
return CheckSymbols::go(doc, context, macroUses);
}
QList<TextEditor::BlockRange> toTextEditorBlocks(
const QList<CPlusPlus::Document::Block> &skippedBlocks)
{
QList<TextEditor::BlockRange> result;
result.reserve(skippedBlocks.size());
foreach (const CPlusPlus::Document::Block &block, skippedBlocks)
result.append(TextEditor::BlockRange(block.utf16charsBegin(), block.utf16charsEnd()));
return result;
}
} // anonymous namespace
namespace CppTools {
BuiltinEditorDocumentProcessor::BuiltinEditorDocumentProcessor(
TextEditor::BaseTextDocument *document,
bool enableSemanticHighlighter)
: BaseEditorDocumentProcessor(document)
, m_parser(new BuiltinEditorDocumentParser(document->filePath()))
, m_semanticInfoUpdater(m_parser.data())
, m_semanticHighlighter(enableSemanticHighlighter
? new CppTools::SemanticHighlighter(document)
: 0)
{
QSharedPointer<Internal::CppCodeModelSettings> cms
= Internal::CppToolsPlugin::instance()->codeModelSettings();
m_parser->setUsePrecompiledHeaders(
cms->pchUsage() != Internal::CppCodeModelSettings::PchUse_None);
if (m_semanticHighlighter) {
m_semanticHighlighter->setHighlightingRunner(
[this]() -> QFuture<TextEditor::HighlightingResult> {
const SemanticInfo semanticInfo = m_semanticInfoUpdater.semanticInfo();
return runHighlighter(semanticInfo.doc, semanticInfo.snapshot,
baseTextDocument()->document());
});
}
connect(cmm(), &Internal::CppModelManager::documentUpdated,
this, &BuiltinEditorDocumentProcessor::onDocumentUpdated);
connect(&m_semanticInfoUpdater, &SemanticInfoUpdater::updated,
this, &BuiltinEditorDocumentProcessor::onSemanticInfoUpdated);
}
BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
{
m_parserFuture.cancel();
m_parserFuture.waitForFinished();
}
void BuiltinEditorDocumentProcessor::run()
{
m_parserFuture = QtConcurrent::run(&runParser, parser(), cmm()->workingCopy());
}
BaseEditorDocumentParser *BuiltinEditorDocumentProcessor::parser()
{
return m_parser.data();
}
void BuiltinEditorDocumentProcessor::semanticRehighlight(bool force)
{
const auto source = createSemanticInfoSource(force);
m_semanticInfoUpdater.updateDetached(source);
}
SemanticInfo BuiltinEditorDocumentProcessor::recalculateSemanticInfo()
{
const auto source = createSemanticInfoSource(false);
return m_semanticInfoUpdater.update(source);
}
bool BuiltinEditorDocumentProcessor::isParserRunning() const
{
return m_parserFuture.isRunning();
}
BuiltinEditorDocumentProcessor *BuiltinEditorDocumentProcessor::get(const QString &filePath)
{
if (BaseEditorDocumentProcessor *b = BaseEditorDocumentProcessor::get(filePath))
return qobject_cast<BuiltinEditorDocumentProcessor *>(b);
return 0;
}
void BuiltinEditorDocumentProcessor::onDocumentUpdated(CPlusPlus::Document::Ptr document)
{
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 (debug) {
qDebug() << "BuiltinEditorDocumentProcessor: document parsed" << document->fileName()
<< document->editorRevision();
}
// Emit ifdefed out blocks
const auto ifdefoutBlocks = toTextEditorBlocks(document->skippedBlocks());
emit ifdefedOutBlocksUpdated(revision(), ifdefoutBlocks);
// Emit code warnings
auto codeWarnings = toTextEditorSelections(document->diagnosticMessages(), textDocument());
emit codeWarningsUpdated(revision(), codeWarnings);
emit cppDocumentUpdated(document);
const auto source = createSemanticInfoSource(false);
m_semanticInfoUpdater.updateDetached(source);
}
void BuiltinEditorDocumentProcessor::onSemanticInfoUpdated(const SemanticInfo semanticInfo)
{
if (debug) {
qDebug() << "BuiltinEditorDocumentProcessor: semantic info updated"
<< semanticInfo.doc->fileName() << semanticInfo.revision << semanticInfo.complete;
}
emit semanticInfoUpdated(semanticInfo);
if (m_semanticHighlighter)
m_semanticHighlighter->run();
}
SemanticInfo::Source BuiltinEditorDocumentProcessor::createSemanticInfoSource(bool force) const
{
const WorkingCopy workingCopy = cmm()->workingCopy();
const QString path = filePath();
return SemanticInfo::Source(path,
workingCopy.source(path),
workingCopy.revision(path),
force);
}
} // namespace CppTools

View File

@@ -0,0 +1,80 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef BUILTINEDITORDOCUMENTPROCESSOR_H
#define BUILTINEDITORDOCUMENTPROCESSOR_H
#include "baseeditordocumentprocessor.h"
#include "builtineditordocumentparser.h"
#include "cppsemanticinfoupdater.h"
#include "cpptools_global.h"
#include "semantichighlighter.h"
#include <utils/qtcoverride.h>
namespace CppTools {
class CPPTOOLS_EXPORT BuiltinEditorDocumentProcessor : public BaseEditorDocumentProcessor
{
Q_OBJECT
BuiltinEditorDocumentProcessor();
public:
BuiltinEditorDocumentProcessor(TextEditor::BaseTextDocument *document,
bool enableSemanticHighlighter = true);
~BuiltinEditorDocumentProcessor();
// BaseEditorDocumentProcessor interface
void run() QTC_OVERRIDE;
void semanticRehighlight(bool force) QTC_OVERRIDE;
CppTools::SemanticInfo recalculateSemanticInfo() QTC_OVERRIDE;
BaseEditorDocumentParser *parser() QTC_OVERRIDE;
bool isParserRunning() const QTC_OVERRIDE;
public:
static BuiltinEditorDocumentProcessor *get(const QString &filePath);
private slots:
void onDocumentUpdated(CPlusPlus::Document::Ptr document);
void onSemanticInfoUpdated(const CppTools::SemanticInfo semanticInfo);
private:
SemanticInfo::Source createSemanticInfoSource(bool force) const;
private:
QScopedPointer<BuiltinEditorDocumentParser> m_parser;
QFuture<void> m_parserFuture;
SemanticInfoUpdater m_semanticInfoUpdater;
QScopedPointer<SemanticHighlighter> m_semanticHighlighter;
};
} // namespace CppTools
#endif // BUILTINEDITORDOCUMENTPROCESSOR_H

View File

@@ -298,6 +298,8 @@ static bool acceptName(NameAST *ast, unsigned *referenceToken)
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context, const QList<CheckSymbols::Result> &macroUses)
{
QTC_ASSERT(doc, return Future());
QTC_ASSERT(doc->translationUnit(), return Future());
QTC_ASSERT(doc->translationUnit()->ast(), return Future());
return (new CheckSymbols(doc, context, macroUses))->start();
}
@@ -477,7 +479,7 @@ bool CheckSymbols::visit(NamespaceAST *ast)
if (!tok.generated()) {
unsigned line, column;
getTokenStartPosition(ast->identifier_token, &line, &column);
Result use(line, column, tok.utf16chars(), CppHighlightingSupport::TypeUse);
Result use(line, column, tok.utf16chars(), SemanticHighlighter::TypeUse);
addUse(use);
}
}
@@ -492,13 +494,13 @@ bool CheckSymbols::visit(UsingDirectiveAST *)
bool CheckSymbols::visit(EnumeratorAST *ast)
{
addUse(ast->identifier_token, CppHighlightingSupport::EnumerationUse);
addUse(ast->identifier_token, SemanticHighlighter::EnumerationUse);
return true;
}
bool CheckSymbols::visit(DotDesignatorAST *ast)
{
addUse(ast->identifier_token, CppHighlightingSupport::FieldUse);
addUse(ast->identifier_token, SemanticHighlighter::FieldUse);
return true;
}
@@ -513,7 +515,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast)
if (funTy->isVirtual()
|| (nameAST->asDestructorName()
&& hasVirtualDestructor(_context.lookupType(funTy->enclosingScope())))) {
addUse(nameAST, CppHighlightingSupport::VirtualMethodUse);
addUse(nameAST, SemanticHighlighter::VirtualMethodUse);
declrIdNameAST = nameAST;
} else if (maybeAddFunction(_context.lookup(decl->name(),
decl->enclosingScope()),
@@ -521,7 +523,7 @@ bool CheckSymbols::visit(SimpleDeclarationAST *ast)
declrIdNameAST = nameAST;
// Add a diagnostic message if non-virtual function has override/final marker
if ((_usages.back().kind != CppHighlightingSupport::VirtualMethodUse)) {
if ((_usages.back().kind != SemanticHighlighter::VirtualMethodUse)) {
if (funTy->isOverride())
warning(declrIdNameAST, QCoreApplication::translate(
"CPlusplus::CheckSymbols", "Only virtual functions can be marked 'override'"));
@@ -559,7 +561,7 @@ bool CheckSymbols::visit(ElaboratedTypeSpecifierAST *ast)
{
accept(ast->attribute_list);
accept(ast->name);
addUse(ast->name, CppHighlightingSupport::TypeUse);
addUse(ast->name, SemanticHighlighter::TypeUse);
return false;
}
@@ -796,14 +798,14 @@ void CheckSymbols::checkName(NameAST *ast, Scope *scope)
if (klass) {
if (hasVirtualDestructor(_context.lookupType(klass))) {
addUse(ast, CppHighlightingSupport::VirtualMethodUse);
addUse(ast, SemanticHighlighter::VirtualMethodUse);
} else {
bool added = false;
if (highlightCtorDtorAsType && maybeType(ast->name))
added = maybeAddTypeOrStatic(_context.lookup(ast->name, klass), ast);
if (!added)
addUse(ast, CppHighlightingSupport::FunctionUse);
addUse(ast, SemanticHighlighter::FunctionUse);
}
}
} else if (maybeType(ast->name) || maybeStatic(ast->name)) {
@@ -853,14 +855,14 @@ bool CheckSymbols::visit(QualifiedNameAST *ast)
if (binding && ast->unqualified_name) {
if (ast->unqualified_name->asDestructorName() != 0) {
if (hasVirtualDestructor(binding)) {
addUse(ast->unqualified_name, CppHighlightingSupport::VirtualMethodUse);
addUse(ast->unqualified_name, SemanticHighlighter::VirtualMethodUse);
} else {
bool added = false;
if (highlightCtorDtorAsType && maybeType(ast->name))
added = maybeAddTypeOrStatic(binding->find(ast->unqualified_name->name),
ast->unqualified_name);
if (!added)
addUse(ast->unqualified_name, CppHighlightingSupport::FunctionUse);
addUse(ast->unqualified_name, SemanticHighlighter::FunctionUse);
}
} else {
QList<LookupItem> items = binding->find(ast->unqualified_name->name);
@@ -904,7 +906,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast)
if (NameAST *class_or_namespace_name = nested_name_specifier->class_or_namespace_name) {
if (TemplateIdAST *template_id = class_or_namespace_name->asTemplateId()) {
if (template_id->template_token) {
addUse(template_id, CppHighlightingSupport::TypeUse);
addUse(template_id, SemanticHighlighter::TypeUse);
binding = 0; // there's no way we can find a binding.
}
@@ -928,7 +930,7 @@ ClassOrNamespace *CheckSymbols::checkNestedName(QualifiedNameAST *ast)
bool CheckSymbols::visit(TypenameTypeParameterAST *ast)
{
addUse(ast->name, CppHighlightingSupport::TypeUse);
addUse(ast->name, SemanticHighlighter::TypeUse);
accept(ast->type_id);
return false;
}
@@ -936,7 +938,7 @@ bool CheckSymbols::visit(TypenameTypeParameterAST *ast)
bool CheckSymbols::visit(TemplateTypeParameterAST *ast)
{
accept(ast->template_parameter_list);
addUse(ast->name, CppHighlightingSupport::TypeUse);
addUse(ast->name, SemanticHighlighter::TypeUse);
accept(ast->type_id);
return false;
}
@@ -988,7 +990,7 @@ bool CheckSymbols::visit(MemInitializerAST *ast)
bool CheckSymbols::visit(GotoStatementAST *ast)
{
if (ast->identifier_token)
addUse(ast->identifier_token, CppHighlightingSupport::LabelUse);
addUse(ast->identifier_token, SemanticHighlighter::LabelUse);
return false;
}
@@ -996,7 +998,7 @@ bool CheckSymbols::visit(GotoStatementAST *ast)
bool CheckSymbols::visit(LabeledStatementAST *ast)
{
if (ast->label_token && !tokenAt(ast->label_token).isKeyword())
addUse(ast->label_token, CppHighlightingSupport::LabelUse);
addUse(ast->label_token, SemanticHighlighter::LabelUse);
accept(ast->statement);
return false;
@@ -1017,7 +1019,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast)
if (id.equalTo(_doc->control()->cpp11Override())
|| id.equalTo(_doc->control()->cpp11Final()))
{
addUse(ast->specifier_token, CppHighlightingSupport::PseudoKeywordUse);
addUse(ast->specifier_token, SemanticHighlighter::PseudoKeywordUse);
}
}
}
@@ -1028,7 +1030,7 @@ bool CheckSymbols::visit(SimpleSpecifierAST *ast)
bool CheckSymbols::visit(ClassSpecifierAST *ast)
{
if (ast->final_token)
addUse(ast->final_token, CppHighlightingSupport::PseudoKeywordUse);
addUse(ast->final_token, SemanticHighlighter::PseudoKeywordUse);
return true;
}
@@ -1053,7 +1055,7 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast)
if (fun->isVirtual()
|| (declId->asDestructorName()
&& hasVirtualDestructor(_context.lookupType(fun->enclosingScope())))) {
addUse(declId, CppHighlightingSupport::VirtualMethodUse);
addUse(declId, SemanticHighlighter::VirtualMethodUse);
} else if (!maybeAddFunction(_context.lookup(fun->name(),
fun->enclosingScope()),
declId, fun->argumentCount())) {
@@ -1161,7 +1163,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast)
unsigned line, column;
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.utf16chars();
const Result use(line, column, length, CppHighlightingSupport::TypeUse);
const Result use(line, column, length, SemanticHighlighter::TypeUse);
addUse(use);
}
@@ -1203,12 +1205,12 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.utf16chars();
Kind kind = CppHighlightingSupport::TypeUse;
Kind kind = SemanticHighlighter::TypeUse;
if (c->enclosingEnum() != 0)
kind = CppHighlightingSupport::EnumerationUse;
kind = SemanticHighlighter::EnumerationUse;
else if (c->isStatic())
// treat static variable as a field(highlighting)
kind = CppHighlightingSupport::FieldUse;
kind = SemanticHighlighter::FieldUse;
const Result use(line, column, length, kind);
addUse(use);
@@ -1245,7 +1247,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a
getTokenStartPosition(startToken, &line, &column);
const unsigned length = tok.utf16chars();
const Result use(line, column, length, CppHighlightingSupport::FieldUse);
const Result use(line, column, length, SemanticHighlighter::FieldUse);
addUse(use);
return true;
@@ -1270,7 +1272,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
return false;
enum { Match_None, Match_TooManyArgs, Match_TooFewArgs, Match_Ok } matchType = Match_None;
Kind kind = CppHighlightingSupport::FunctionUse;
Kind kind = SemanticHighlighter::FunctionUse;
foreach (const LookupItem &r, candidates) {
Symbol *c = r.declaration();
@@ -1297,21 +1299,21 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
if (argumentCount < funTy->minimumArgumentCount()) {
if (matchType != Match_Ok) {
kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse;
kind = funTy->isVirtual() ? SemanticHighlighter::VirtualMethodUse : SemanticHighlighter::FunctionUse;
matchType = Match_TooFewArgs;
}
} else if (argumentCount > funTy->argumentCount() && !funTy->isVariadic()) {
if (matchType != Match_Ok) {
matchType = Match_TooManyArgs;
kind = funTy->isVirtual() ? CppHighlightingSupport::VirtualMethodUse : CppHighlightingSupport::FunctionUse;
kind = funTy->isVirtual() ? SemanticHighlighter::VirtualMethodUse : SemanticHighlighter::FunctionUse;
}
} else if (!funTy->isVirtual()) {
matchType = Match_Ok;
kind = CppHighlightingSupport::FunctionUse;
kind = SemanticHighlighter::FunctionUse;
//continue, to check if there is a matching candidate which is virtual
} else {
matchType = Match_Ok;
kind = CppHighlightingSupport::VirtualMethodUse;
kind = SemanticHighlighter::VirtualMethodUse;
break;
}
}
@@ -1321,7 +1323,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
if (highlightCtorDtorAsType
&& (isConstructor || isDestructor)
&& maybeType(ast->name)
&& kind == CppHighlightingSupport::FunctionUse) {
&& kind == SemanticHighlighter::FunctionUse) {
return false;
}

View File

@@ -31,8 +31,8 @@
#define CPLUSPLUSCHECKSYMBOLS_H
#include "cpptools_global.h"
#include "cpphighlightingsupport.h"
#include "cppsemanticinfo.h"
#include "semantichighlighter.h"
#include <cplusplus/TypeOfExpression.h>
@@ -51,7 +51,7 @@ public:
virtual ~CheckSymbols();
typedef TextEditor::HighlightingResult Result;
typedef CppHighlightingSupport::Kind Kind;
typedef SemanticHighlighter::Kind Kind;
virtual void run();

View File

@@ -102,8 +102,8 @@ public:
{
QStringList completions;
CppCompletionAssistInterface *ai
= new CppCompletionAssistInterface(m_editorWidget->document(), m_position,
m_editorWidget->textDocument()->filePath(),
= new CppCompletionAssistInterface(m_editorWidget->textDocument()->filePath(),
m_editorWidget->document(), m_position,
ExplicitlyInvoked, m_snapshot,
ProjectPart::HeaderPaths());
CppCompletionAssistProcessor processor;

View File

@@ -34,8 +34,8 @@
#include "cppmodelmanager.h"
#include "cppmodelmanagerinterface.h"
#include "cpptoolsconstants.h"
#include "cpptoolseditorsupport.h"
#include "cpptoolsreuse.h"
#include "editordocumenthandle.h"
#include <coreplugin/icore.h>
#include <cppeditor/cppeditorconstants.h>
@@ -421,15 +421,14 @@ IAssistProcessor *InternalCompletionAssistProvider::createProcessor() const
}
TextEditor::IAssistInterface *InternalCompletionAssistProvider::createAssistInterface(
ProjectExplorer::Project *project, BaseTextEditor *editor, QTextDocument *document,
ProjectExplorer::Project *project, const QString &filePath, QTextDocument *document,
bool isObjCEnabled, int position, TextEditor::AssistReason reason) const
{
Q_UNUSED(project);
QTC_ASSERT(editor, return 0);
QTC_ASSERT(document, return 0);
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
return new CppTools::Internal::CppCompletionAssistInterface(editor, document, isObjCEnabled,
return new CppTools::Internal::CppCompletionAssistInterface(filePath, document, isObjCEnabled,
position, reason,
modelManager->workingCopy());
}
@@ -1957,12 +1956,9 @@ void CppCompletionAssistInterface::getCppSpecifics() const
return;
m_gotCppSpecifics = true;
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
if (CppEditorSupport *supp = modelManager->cppEditorSupport(m_editor)) {
if (BuiltinEditorDocumentParser::Ptr parser = supp->documentParser()) {
parser->update(m_workingCopy);
m_snapshot = parser->snapshot();
m_headerPaths = parser->headerPaths();
}
if (BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(fileName())) {
parser->update(m_workingCopy);
m_snapshot = parser->snapshot();
m_headerPaths = parser->headerPaths();
}
}

View File

@@ -96,7 +96,7 @@ public:
TextEditor::IAssistProcessor *createProcessor() const QTC_OVERRIDE;
TextEditor::IAssistInterface *createAssistInterface(ProjectExplorer::Project *project,
TextEditor::BaseTextEditor *editor,
const QString &filePath,
QTextDocument *document,
bool isObjCEnabled,
int position,
@@ -173,28 +173,25 @@ private:
class CppCompletionAssistInterface : public TextEditor::DefaultAssistInterface
{
public:
CppCompletionAssistInterface(TextEditor::BaseTextEditor *editor,
CppCompletionAssistInterface(const QString &filePath,
QTextDocument *textDocument,
bool isObjCEnabled,
int position,
TextEditor::AssistReason reason,
const WorkingCopy &workingCopy)
: TextEditor::DefaultAssistInterface(textDocument, position, editor->document()->filePath(),
reason)
, m_editor(editor)
: TextEditor::DefaultAssistInterface(textDocument, position, filePath, reason)
, m_isObjCEnabled(isObjCEnabled)
, m_gotCppSpecifics(false)
, m_workingCopy(workingCopy)
{}
CppCompletionAssistInterface(QTextDocument *textDocument,
CppCompletionAssistInterface(const QString &filePath,
QTextDocument *textDocument,
int position,
const QString &fileName,
TextEditor::AssistReason reason,
const CPlusPlus::Snapshot &snapshot,
const ProjectPart::HeaderPaths &headerPaths)
: TextEditor::DefaultAssistInterface(textDocument, position, fileName, reason)
, m_editor(0)
: TextEditor::DefaultAssistInterface(textDocument, position, filePath, reason)
, m_isObjCEnabled(false)
, m_gotCppSpecifics(true)
, m_snapshot(snapshot)
@@ -210,7 +207,6 @@ public:
private:
void getCppSpecifics() const;
TextEditor::BaseTextEditor *m_editor;
mutable bool m_isObjCEnabled;
mutable bool m_gotCppSpecifics;
WorkingCopy m_workingCopy;

View File

@@ -61,7 +61,7 @@ public:
bool isContinuationChar(const QChar &c) const QTC_OVERRIDE;
virtual TextEditor::IAssistInterface *createAssistInterface(
ProjectExplorer::Project *project, TextEditor::BaseTextEditor *editor,
ProjectExplorer::Project *project, const QString &filePath,
QTextDocument *document, bool isObjCEnabled, int position,
TextEditor::AssistReason reason) const = 0;

View File

@@ -1,104 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "cpphighlightingsupportinternal.h"
#include "cppchecksymbols.h"
#include "cpptoolsreuse.h"
#include <texteditor/basetextdocument.h>
#include <texteditor/convenience.h>
#include <cplusplus/SimpleLexer.h>
using namespace CPlusPlus;
using namespace CppTools;
using namespace CppTools::Internal;
CppHighlightingSupportInternal::CppHighlightingSupportInternal(
TextEditor::BaseTextDocument *baseTextDocument)
: CppHighlightingSupport(baseTextDocument)
{
}
CppHighlightingSupportInternal::~CppHighlightingSupportInternal()
{
}
QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highlightingFuture(
const Document::Ptr &doc,
const Snapshot &snapshot) const
{
typedef TextEditor::HighlightingResult Result;
QList<Result> macroUses;
QTextDocument *textDocument = baseTextDocument()->document();
using TextEditor::Convenience::convertPosition;
// Get macro definitions
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
int line, column;
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, macro.nameToQString().size(), MacroUse);
macroUses.append(use);
}
// Get macro uses
foreach (const Document::MacroUse &macro, doc->macroUses()) {
const QString name = macro.macro().nameToQString();
//Filter out QtKeywords
if (isQtKeyword(QStringRef(&name)))
continue;
// Filter out C++ keywords
// FIXME: Check default values or get from document.
LanguageFeatures features;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const QList<Token> tokens = tokenize(name);
if (tokens.length() && (tokens.at(0).isKeyword() || tokens.at(0).isObjCAtKeyword()))
continue;
int line, column;
convertPosition(textDocument, macro.utf16charsBegin(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, name.size(), MacroUse);
macroUses.append(use);
}
LookupContext context(doc, snapshot);
return CheckSymbols::go(doc, context, macroUses);
}

View File

@@ -27,8 +27,8 @@
**
****************************************************************************/
#include "cpphighlightingsupport.h"
#include "cpplocalsymbols.h"
#include "semantichighlighter.h"
#include "cppsemanticinfo.h"
@@ -86,7 +86,7 @@ protected:
getPosition(token.utf16charsBegin(), &line, &column);
localUses[member].append(
HighlightingResult(line, column, token.utf16chars(),
CppHighlightingSupport::LocalUse));
SemanticHighlighter::LocalUse));
}
}
}
@@ -110,7 +110,7 @@ protected:
getTokenStartPosition(simpleName->identifier_token, &line, &column);
localUses[member].append(
HighlightingResult(line, column, token.utf16chars(),
CppHighlightingSupport::LocalUse));
SemanticHighlighter::LocalUse));
return false;
}
}

View File

@@ -34,13 +34,12 @@
#include "cppcodemodelinspectordumper.h"
#include "cppcodemodelsettings.h"
#include "cppfindreferences.h"
#include "cpphighlightingsupport.h"
#include "cppindexingsupport.h"
#include "cppmodelmanagersupportinternal.h"
#include "cppsourceprocessor.h"
#include "cpptoolsconstants.h"
#include "cpptoolseditorsupport.h"
#include "cpptoolsplugin.h"
#include "editordocumenthandle.h"
#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
@@ -399,47 +398,42 @@ void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupp
m_extraEditorSupports.remove(editorSupport);
}
/// \brief Returns the \c CppEditorSupport for the given text editor. It will
/// create one when none exists yet.
CppEditorSupport *CppModelManager::cppEditorSupport(TextEditor::BaseTextEditor *textEditor)
EditorDocumentHandle *CppModelManager::editorDocument(const QString &filePath)
{
Q_ASSERT(textEditor);
QTC_ASSERT(!filePath.isEmpty(), return 0);
QMutexLocker locker(&m_cppEditorSupportsMutex);
CppEditorSupport *editorSupport = m_cppEditorSupports.value(textEditor, 0);
if (!editorSupport && isCppEditor(textEditor)) {
editorSupport = new CppEditorSupport(this, textEditor);
m_cppEditorSupports.insert(textEditor, editorSupport);
}
return editorSupport;
QMutexLocker locker(&m_cppEditorsMutex);
return m_cppEditors.value(filePath, 0);
}
/// \brief Removes the CppEditorSupport for the closed editor.
void CppModelManager::deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor)
void CppModelManager::registerEditorDocument(EditorDocumentHandle *editorDocument)
{
static short numberOfClosedEditors = 0;
QTC_ASSERT(editorDocument, return);
const QString filePath = editorDocument->filePath();
QTC_ASSERT(!filePath.isEmpty(), return);
QTC_ASSERT(textEditor, return);
QMutexLocker locker(&m_cppEditorsMutex);
QTC_ASSERT(m_cppEditors.value(filePath, 0) == 0, return);
m_cppEditors.insert(filePath, editorDocument);
}
if (!isCppEditor(textEditor))
return;
void CppModelManager::unregisterEditorDocument(const QString &filePath)
{
QTC_ASSERT(!filePath.isEmpty(), return);
CppEditorSupport *editorSupport;
int numberOfOpenEditors = 0;
static short closedCppDocuments = 0;
int openCppDocuments = 0;
{ // Only lock the operations on m_cppEditorSupport
QMutexLocker locker(&m_cppEditorSupportsMutex);
editorSupport = m_cppEditorSupports.value(textEditor, 0);
m_cppEditorSupports.remove(textEditor);
numberOfOpenEditors = m_cppEditorSupports.size();
{
QMutexLocker locker(&m_cppEditorsMutex);
QTC_ASSERT(m_cppEditors.value(filePath, 0), return);
QTC_CHECK(m_cppEditors.remove(filePath) == 1);
openCppDocuments = m_cppEditors.size();
}
delete editorSupport;
++numberOfClosedEditors;
if (numberOfOpenEditors == 0 || numberOfClosedEditors == 5) {
numberOfClosedEditors = 0;
++closedCppDocuments;
if (openCppDocuments == 0 || closedCppDocuments == 5) {
closedCppDocuments = 0;
delayedGC();
}
}
@@ -483,10 +477,8 @@ WorkingCopy CppModelManager::buildWorkingCopyList()
{
WorkingCopy workingCopy;
foreach (const CppEditorSupport *editorSupport, cppEditorSupportList()) {
workingCopy.insert(editorSupport->fileName(), editorSupport->contents(),
editorSupport->editorRevision());
}
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
workingCopy.insert(cppEditor->filePath(), cppEditor->contents(), cppEditor->revision());
QSetIterator<AbstractEditorSupport *> it(m_extraEditorSupports);
while (it.hasNext()) {
@@ -551,10 +543,10 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec
}
}
QList<CppEditorSupport *> CppModelManager::cppEditorSupportList() const
QList<EditorDocumentHandle *> CppModelManager::cppEditors() const
{
QMutexLocker locker(&m_cppEditorSupportsMutex);
return m_cppEditorSupports.values();
QMutexLocker locker(&m_cppEditorsMutex);
return m_cppEditors.values();
}
/// \brief Remove all given files from the snapshot.
@@ -832,8 +824,8 @@ void CppModelManager::GC()
// Collect files of CppEditorSupport and AbstractEditorSupport.
QStringList filesInEditorSupports;
foreach (const CppEditorSupport *cppEditorSupport, cppEditorSupportList())
filesInEditorSupports << cppEditorSupport->fileName();
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
filesInEditorSupports << cppEditor->filePath();
QSetIterator<AbstractEditorSupport *> jt(m_extraEditorSupports);
while (jt.hasNext()) {
@@ -909,13 +901,13 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(const QSt
return cms->completionAssistProvider();
}
CppHighlightingSupport *CppModelManager::highlightingSupport(
BaseEditorDocumentProcessor *CppModelManager::editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument) const
{
QTC_ASSERT(baseTextDocument, return 0);
ModelManagerSupport *cms = modelManagerSupportForMimeType(baseTextDocument->mimeType());
QTC_ASSERT(cms, return 0);
return cms->highlightingSupport(baseTextDocument);
return cms->editorDocumentProcessor(baseTextDocument);
}
void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport)
@@ -934,27 +926,3 @@ void CppModelManager::enableGarbageCollector(bool enable)
m_delayedGcTimer->stop();
m_enableGC = enable;
}
bool CppModelManager::setExtraDiagnostics(const QString &fileName,
const QString &kind,
const QList<Document::DiagnosticMessage> &diagnostics)
{
foreach (CppEditorSupport *editorSupport, cppEditorSupportList()) {
if (editorSupport->fileName() == fileName) {
editorSupport->setExtraDiagnostics(kind, diagnostics);
return true;
}
}
return false;
}
void CppModelManager::setIfdefedOutBlocks(const QString &fileName,
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks)
{
foreach (CppEditorSupport *editorSupport, cppEditorSupportList()) {
if (editorSupport->fileName() == fileName) {
editorSupport->setIfdefedOutBlocks(ifdeffedOutBlocks);
break;
}
}
}

View File

@@ -44,8 +44,6 @@ namespace TextEditor { class BaseTextEditorWidget; }
namespace CppTools {
class CppEditorSupport;
namespace Internal {
class CppFindReferences;
@@ -94,8 +92,10 @@ public:
virtual void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
virtual void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor);
virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor);
virtual EditorDocumentHandle *editorDocument(const QString &filePath);
virtual void registerEditorDocument(EditorDocumentHandle *editorDocument);
virtual void unregisterEditorDocument(const QString &filePath);
virtual QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
@@ -106,18 +106,13 @@ public:
virtual void findMacroUsages(const CPlusPlus::Macro &macro);
virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
virtual bool setExtraDiagnostics(const QString &fileName, const QString &key,
const QList<Document::DiagnosticMessage> &diagnostics);
virtual void setIfdefedOutBlocks(const QString &fileName,
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks);
void finishedRefreshingSourceFiles(const QStringList &files);
virtual void finishedRefreshingSourceFiles(const QStringList &files);
virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport);
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
virtual CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) const;
virtual BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument) const;
virtual void setIndexingSupport(CppIndexingSupport *indexingSupport);
virtual CppIndexingSupport *indexingSupport();
@@ -176,7 +171,7 @@ private:
void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
QList<CppEditorSupport *> cppEditorSupportList() const;
QList<EditorDocumentHandle *> cppEditors() const;
WorkingCopy buildWorkingCopyList();
@@ -208,8 +203,8 @@ private:
QByteArray m_definedMacros;
// Editor integration
mutable QMutex m_cppEditorSupportsMutex;
QMap<TextEditor::BaseTextEditor *, CppEditorSupport *> m_cppEditorSupports;
mutable QMutex m_cppEditorsMutex;
QMap<QString, EditorDocumentHandle *> m_cppEditors;
QSet<AbstractEditorSupport *> m_extraEditorSupports;
// Completion & highlighting

View File

@@ -27,10 +27,11 @@
**
****************************************************************************/
#include "builtineditordocumentparser.h"
#include "cppsourceprocessor.h"
#include "cpptoolseditorsupport.h"
#include "cpptoolsplugin.h"
#include "cpptoolstestcase.h"
#include "editordocumenthandle.h"
#include "modelmanagertesthelper.h"
#include <coreplugin/editormanager/editormanager.h>
@@ -865,10 +866,10 @@ void CppToolsPlugin::test_modelmanager_defines_per_project()
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport(
qobject_cast<TextEditor::BaseTextEditor *>(editor));
while (sup->lastSemanticInfoDocument().isNull())
QCoreApplication::processEvents();
// CppEditorSupport *sup = mm->cppEditorSupport(
// qobject_cast<TextEditor::BaseTextEditor *>(editor));
// while (sup->lastSemanticInfoDocument().isNull())
// QCoreApplication::processEvents();
Document::Ptr doc = mm->document(fileName);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);
@@ -942,20 +943,16 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport(
qobject_cast<TextEditor::BaseTextEditor *>(editor));
while (sup->lastSemanticInfoDocument().isNull())
QCoreApplication::processEvents();
sup->documentParser()->setUsePrecompiledHeaders(true);
sup->documentParser()->update(mm->workingCopy());
BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(fileName);
parser->setUsePrecompiledHeaders(true);
parser->update(mm->workingCopy());
// Check if defines from pch are considered
Document::Ptr document = mm->document(fileName);
QCOMPARE(nameOfFirstDeclaration(document), firstDeclarationName);
// Check if declarations from pch are considered
CPlusPlus::LookupContext context(document, sup->documentParser()->snapshot());
CPlusPlus::LookupContext context(document, parser->snapshot());
const CPlusPlus::Identifier *identifier
= document->control()->identifier(firstClassInPchFile.data());
const QList<CPlusPlus::LookupItem> results = context.lookup(identifier,
@@ -1025,13 +1022,10 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor));
CppEditorSupport *sup = mm->cppEditorSupport(
qobject_cast<TextEditor::BaseTextEditor *>(editor));
while (sup->lastSemanticInfoDocument().isNull())
QCoreApplication::processEvents();
sup->documentParser()->setEditorDefines(editorDefines.toUtf8());
sup->documentParser()->update(mm->workingCopy());
const QString filePath = editor->document()->filePath();
BaseEditorDocumentParser *parser = BaseEditorDocumentParser::get(filePath);
parser->setEditorDefines(editorDefines.toUtf8());
parser->update(mm->workingCopy());
Document::Ptr doc = mm->document(main1File);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);

View File

@@ -52,9 +52,9 @@ namespace Utils { class FileName; }
namespace CppTools {
class AbstractEditorSupport;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class CppEditorSupport;
class CppHighlightingSupport;
class EditorDocumentHandle;
class CppIndexingSupport;
class ModelManagerSupport;
class WorkingCopy;
@@ -95,8 +95,10 @@ public:
virtual void addExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual void removeExtraEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0;
virtual CppEditorSupport *cppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
virtual void deleteCppEditorSupport(TextEditor::BaseTextEditor *textEditor) = 0;
virtual EditorDocumentHandle *editorDocument(const QString &filePath) = 0;
virtual void registerEditorDocument(EditorDocumentHandle *editorDocument) = 0;
virtual void unregisterEditorDocument(const QString &filePath) = 0;
virtual QList<int> references(CPlusPlus::Symbol *symbol,
const CPlusPlus::LookupContext &context) = 0;
@@ -108,14 +110,13 @@ public:
virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement = QString()) = 0;
virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;
virtual void setIfdefedOutBlocks(const QString &fileName,
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
virtual void finishedRefreshingSourceFiles(const QStringList &files) = 0;
virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport) = 0;
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const = 0;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) const = 0;
virtual BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument) const = 0;
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
virtual CppIndexingSupport *indexingSupport() = 0;

View File

@@ -38,8 +38,8 @@ namespace TextEditor { class BaseTextDocument; }
namespace CppTools {
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class CppHighlightingSupport;
class CPPTOOLS_EXPORT ModelManagerSupport
{
@@ -50,8 +50,8 @@ public:
virtual QString displayName() const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider() = 0;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) = 0;
virtual BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument) = 0;
};
} // CppTools namespace

View File

@@ -28,8 +28,8 @@
****************************************************************************/
#include "cppcompletionassist.h"
#include "cpphighlightingsupportinternal.h"
#include "cppmodelmanagersupportinternal.h"
#include "builtineditordocumentprocessor.h"
#include <QCoreApplication>
@@ -56,13 +56,13 @@ QString ModelManagerSupportInternal::displayName() const
"Qt Creator Built-in");
}
BaseEditorDocumentProcessor *ModelManagerSupportInternal::editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument)
{
return new BuiltinEditorDocumentProcessor(baseTextDocument);
}
CppCompletionAssistProvider *ModelManagerSupportInternal::completionAssistProvider()
{
return m_completionAssistProvider.data();
}
CppHighlightingSupport *ModelManagerSupportInternal::highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument)
{
return new CppHighlightingSupportInternal(baseTextDocument);
}

View File

@@ -49,8 +49,8 @@ public:
virtual QString displayName() const;
virtual CppCompletionAssistProvider *completionAssistProvider();
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument);
virtual BaseEditorDocumentProcessor *editorDocumentProcessor(
TextEditor::BaseTextDocument *baseTextDocument);
private:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;

View File

@@ -32,6 +32,6 @@
using namespace CppTools;
SemanticInfo::SemanticInfo()
: revision(0), forced(false), complete(true)
: revision(0), complete(true), localUsesUpdated(false)
{
}

View File

@@ -45,28 +45,22 @@ class CPPTOOLS_EXPORT SemanticInfo
public:
struct Source
{
const CPlusPlus::Snapshot snapshot;
const QString fileName;
const QByteArray code;
const int line;
const int column;
const unsigned revision;
const bool force;
Source()
: line(0), column(0), revision(0), force(false)
{ }
Source() : revision(0), force(false) {}
Source(const CPlusPlus::Snapshot &snapshot,
const QString &fileName,
Source(const QString &fileName,
const QByteArray &code,
int line, int column,
unsigned revision,
bool force)
: snapshot(snapshot), fileName(fileName),
code(code), line(line), column(column),
revision(revision), force(force)
{ }
: fileName(fileName)
, code(code)
, revision(revision)
, force(force)
{}
};
public:
@@ -78,10 +72,12 @@ public:
SemanticInfo();
unsigned revision;
bool forced;
bool complete;
CPlusPlus::Snapshot snapshot;
CPlusPlus::Document::Ptr doc;
// Widget specific (e.g. related to cursor position)
bool localUsesUpdated;
LocalUseMap localUses;
};

View File

@@ -0,0 +1,226 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "builtineditordocumentparser.h"
#include "cpplocalsymbols.h"
#include "cppsemanticinfoupdater.h"
#include <utils/qtcassert.h>
#include <utils/qtcoverride.h>
#include <utils/runextensions.h>
#include <cplusplus/Control.h>
#include <cplusplus/CppDocument.h>
#include <cplusplus/TranslationUnit.h>
enum { debug = 0 };
using namespace CPlusPlus;
using namespace CppTools;
namespace CppTools {
class SemanticInfoUpdaterPrivate
{
public:
class FuturizedTopLevelDeclarationProcessor: public CPlusPlus::TopLevelDeclarationProcessor
{
public:
FuturizedTopLevelDeclarationProcessor(QFutureInterface<void> &future): m_future(future) {}
bool processDeclaration(CPlusPlus::DeclarationAST *) { return !isCanceled(); }
bool isCanceled() { return m_future.isCanceled(); }
private:
QFutureInterface<void> m_future;
};
public:
SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q, BuiltinEditorDocumentParser *m_parser);
~SemanticInfoUpdaterPrivate();
SemanticInfo semanticInfo() const;
void setSemanticInfo(const SemanticInfo &semanticInfo, bool emitSignal);
SemanticInfo update(const SemanticInfo::Source &source,
bool emitSignalWhenFinished,
FuturizedTopLevelDeclarationProcessor *processor);
bool reuseCurrentSemanticInfo(const SemanticInfo::Source &source, bool emitSignalWhenFinished);
void update_helper(QFutureInterface<void> &future, const SemanticInfo::Source source);
public:
SemanticInfoUpdater *q;
mutable QMutex m_lock;
SemanticInfo m_semanticInfo;
QFuture<void> m_future;
BuiltinEditorDocumentParser *m_parser;
};
SemanticInfoUpdaterPrivate::SemanticInfoUpdaterPrivate(SemanticInfoUpdater *q,
BuiltinEditorDocumentParser *parser)
: q(q)
, m_parser(parser)
{
}
SemanticInfoUpdaterPrivate::~SemanticInfoUpdaterPrivate()
{
m_future.cancel();
m_future.waitForFinished();
}
SemanticInfo SemanticInfoUpdaterPrivate::semanticInfo() const
{
QMutexLocker locker(&m_lock);
return m_semanticInfo;
}
void SemanticInfoUpdaterPrivate::setSemanticInfo(const SemanticInfo &semanticInfo, bool emitSignal)
{
{
QMutexLocker locker(&m_lock);
m_semanticInfo = semanticInfo;
}
if (emitSignal) {
if (debug)
qDebug() << "SemanticInfoUpdater: emiting new info";
emit q->updated(semanticInfo);
}
}
SemanticInfo SemanticInfoUpdaterPrivate::update(const SemanticInfo::Source &source,
bool emitSignalWhenFinished,
FuturizedTopLevelDeclarationProcessor *processor)
{
if (debug)
qDebug() << "SemanticInfoUpdater: update() - source revision" << source.revision;
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);
Document::Ptr doc = newSemanticInfo.snapshot.preprocessedDocument(source.code, source.fileName);
if (processor)
doc->control()->setTopLevelDeclarationProcessor(processor);
doc->check();
if (processor && processor->isCanceled())
newSemanticInfo.complete = false;
newSemanticInfo.doc = doc;
if (debug)
qDebug() << "SemanticInfoUpdater: update() - re-calculated document. Canceled ="
<< !newSemanticInfo.complete;
setSemanticInfo(newSemanticInfo, emitSignalWhenFinished);
return newSemanticInfo;
}
bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::Source &source,
bool emitSignalWhenFinished)
{
const SemanticInfo currentSemanticInfo = semanticInfo();
if (!source.force
&& currentSemanticInfo.complete
&& currentSemanticInfo.revision == source.revision
&& currentSemanticInfo.doc
&& currentSemanticInfo.doc->translationUnit()->ast()
&& currentSemanticInfo.doc->fileName() == source.fileName) {
SemanticInfo newSemanticInfo;
newSemanticInfo.revision = source.revision;
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"
<< source.revision;
return true;
}
return false;
}
void SemanticInfoUpdaterPrivate::update_helper(QFutureInterface<void> &future,
const SemanticInfo::Source source)
{
FuturizedTopLevelDeclarationProcessor processor(future);
update(source, true, &processor);
}
SemanticInfoUpdater::SemanticInfoUpdater(BuiltinEditorDocumentParser *parser)
: d(new SemanticInfoUpdaterPrivate(this, parser))
{
}
SemanticInfoUpdater::~SemanticInfoUpdater()
{
d->m_future.cancel();
d->m_future.waitForFinished();
}
SemanticInfo SemanticInfoUpdater::update(const SemanticInfo::Source &source)
{
if (debug)
qDebug() << "SemanticInfoUpdater: update() - synchronous";
d->m_future.cancel();
const bool emitSignalWhenFinished = false;
if (d->reuseCurrentSemanticInfo(source, emitSignalWhenFinished)) {
d->m_future = QFuture<void>();
return semanticInfo();
}
return d->update(source, emitSignalWhenFinished, 0);
}
void SemanticInfoUpdater::updateDetached(const SemanticInfo::Source source)
{
if (debug)
qDebug() << "SemanticInfoUpdater: updateDetached() - asynchronous";
d->m_future.cancel();
const bool emitSignalWhenFinished = true;
if (d->reuseCurrentSemanticInfo(source, emitSignalWhenFinished)) {
d->m_future = QFuture<void>();
return;
}
d->m_future = QtConcurrent::run<SemanticInfoUpdaterPrivate, void, const SemanticInfo::Source>
(&SemanticInfoUpdaterPrivate::update_helper, d.data(), source);
}
SemanticInfo SemanticInfoUpdater::semanticInfo() const
{
return d->semanticInfo();
}
} // namespace CppTools

View File

@@ -27,37 +27,40 @@
**
****************************************************************************/
#ifndef CPPTOOLS_CPPHIGHLIGHTINGSUPPORTINTERNAL_H
#define CPPTOOLS_CPPHIGHLIGHTINGSUPPORTINTERNAL_H
#ifndef CPPSEMANTICINFOUPDATER_H
#define CPPSEMANTICINFOUPDATER_H
#include "cpphighlightingsupport.h"
#include "cppsemanticinfo.h"
#include <QFuture>
#include <QObject>
#include <QScopedPointer>
namespace CppTools {
namespace Internal {
class CppHighlightingSupportInternal: public CppHighlightingSupport
class BuiltinEditorDocumentParser;
class SemanticInfoUpdaterPrivate;
class SemanticInfoUpdater : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(SemanticInfoUpdater)
public:
CppHighlightingSupportInternal(TextEditor::BaseTextDocument *baseTextDocument);
virtual ~CppHighlightingSupportInternal();
explicit SemanticInfoUpdater(BuiltinEditorDocumentParser *parser);
~SemanticInfoUpdater();
virtual bool requiresSemanticInfo() const
{ return true; }
SemanticInfo semanticInfo() const;
virtual bool hightlighterHandlesDiagnostics() const
{ return false; }
SemanticInfo update(const SemanticInfo::Source &source);
void updateDetached(const SemanticInfo::Source source);
virtual bool hightlighterHandlesIfdefedOutBlocks() const
{ return false; }
signals:
void updated(CppTools::SemanticInfo semanticInfo);
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const;
private:
QScopedPointer<SemanticInfoUpdaterPrivate> d;
};
} // namespace Internal
} // namespace CppTools
#endif // CPPTOOLS_CPPHIGHLIGHTINGSUPPORTINTERNAL_H
#endif // CPPSEMANTICINFOUPDATER_H

View File

@@ -33,8 +33,8 @@
#include "cppmodelmanager.h"
#include "cppsourceprocessertesthelper.h"
#include "cppsourceprocessor.h"
#include "cpptoolseditorsupport.h"
#include "cpptoolstestcase.h"
#include "editordocumenthandle.h"
#include <texteditor/basetexteditor.h>
@@ -140,13 +140,11 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic()
QVERIFY(testCase.openBaseTextEditor(fileName1, &editor));
testCase.closeEditorAtEndOfTestCase(editor);
// Get editor snapshot
CppEditorSupport *cppEditorSupport = CppModelManagerInterface::instance()
->cppEditorSupport(editor);
QVERIFY(cppEditorSupport);
BuiltinEditorDocumentParser::Ptr documentParser = cppEditorSupport->documentParser();
QVERIFY(documentParser);
Snapshot snapshot = documentParser->snapshot();
// Check editor snapshot
const QString filePath = editor->document()->filePath();
BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(filePath);
QVERIFY(parser);
Snapshot snapshot = parser->snapshot();
QCOMPARE(snapshot.size(), 3); // Configuration file included
// Check includes

View File

@@ -5,7 +5,9 @@ include(../../qtcreatorplugin.pri)
HEADERS += \
abstracteditorsupport.h \
baseeditordocumentparser.h \
baseeditordocumentprocessor.h \
builtineditordocumentparser.h \
builtineditordocumentprocessor.h \
builtinindexingsupport.h \
commentssettings.h \
completionsettingspage.h \
@@ -26,8 +28,6 @@ HEADERS += \
cppfilesettingspage.h \
cppfindreferences.h \
cppfunctionsfilter.h \
cpphighlightingsupport.h \
cpphighlightingsupportinternal.h \
cppindexingsupport.h \
cpplocalsymbols.h \
cpplocatordata.h \
@@ -42,20 +42,22 @@ HEADERS += \
cppqtstyleindenter.h \
cpprefactoringchanges.h \
cppsemanticinfo.h \
cppsemanticinfoupdater.h \
cppsourceprocessor.h \
cpptools_global.h \
cpptoolsconstants.h \
cpptoolseditorsupport.h \
cpptoolsplugin.h \
cpptoolsreuse.h \
cpptoolssettings.h \
cppworkingcopy.h \
doxygengenerator.h \
editordocumenthandle.h \
functionutils.h \
includeutils.h \
indexitem.h \
insertionpointlocator.h \
searchsymbols.h \
semantichighlighter.h \
stringtable.h \
symbolfinder.h \
symbolsfindfilter.h \
@@ -64,7 +66,9 @@ HEADERS += \
SOURCES += \
abstracteditorsupport.cpp \
baseeditordocumentparser.cpp \
baseeditordocumentprocessor.cpp \
builtineditordocumentparser.cpp \
builtineditordocumentprocessor.cpp \
builtinindexingsupport.cpp \
commentssettings.cpp \
completionsettingspage.cpp \
@@ -85,8 +89,6 @@ SOURCES += \
cppfilesettingspage.cpp \
cppfindreferences.cpp \
cppfunctionsfilter.cpp \
cpphighlightingsupport.cpp \
cpphighlightingsupportinternal.cpp \
cppindexingsupport.cpp \
cpplocalsymbols.cpp \
cpplocatordata.cpp \
@@ -101,18 +103,20 @@ SOURCES += \
cppqtstyleindenter.cpp \
cpprefactoringchanges.cpp \
cppsemanticinfo.cpp \
cppsemanticinfoupdater.cpp \
cppsourceprocessor.cpp \
cpptoolseditorsupport.cpp \
cpptoolsplugin.cpp \
cpptoolsreuse.cpp \
cpptoolssettings.cpp \
cppworkingcopy.cpp \
doxygengenerator.cpp \
editordocumenthandle.cpp \
functionutils.cpp \
includeutils.cpp \
indexitem.cpp \
insertionpointlocator.cpp \
searchsymbols.cpp \
semantichighlighter.cpp \
stringtable.cpp \
symbolfinder.cpp \
symbolsfindfilter.cpp \

View File

@@ -25,7 +25,9 @@ QtcPlugin {
files: [
"abstracteditorsupport.cpp", "abstracteditorsupport.h",
"baseeditordocumentparser.cpp", "baseeditordocumentparser.h",
"baseeditordocumentprocessor.cpp", "baseeditordocumentprocessor.h",
"builtineditordocumentparser.cpp", "builtineditordocumentparser.h",
"builtineditordocumentprocessor.cpp", "builtineditordocumentprocessor.h",
"builtinindexingsupport.cpp", "builtinindexingsupport.h",
"commentssettings.cpp", "commentssettings.h",
"completionsettingspage.cpp", "completionsettingspage.h", "completionsettingspage.ui",
@@ -46,8 +48,6 @@ QtcPlugin {
"cppfilesettingspage.cpp", "cppfilesettingspage.h", "cppfilesettingspage.ui",
"cppfindreferences.cpp", "cppfindreferences.h",
"cppfunctionsfilter.cpp", "cppfunctionsfilter.h",
"cpphighlightingsupport.cpp", "cpphighlightingsupport.h",
"cpphighlightingsupportinternal.cpp", "cpphighlightingsupportinternal.h",
"cppindexingsupport.cpp", "cppindexingsupport.h",
"cpplocalsymbols.cpp", "cpplocalsymbols.h",
"cpplocatordata.cpp", "cpplocatordata.h",
@@ -62,21 +62,23 @@ QtcPlugin {
"cppqtstyleindenter.cpp", "cppqtstyleindenter.h",
"cpprefactoringchanges.cpp", "cpprefactoringchanges.h",
"cppsemanticinfo.cpp", "cppsemanticinfo.h",
"cppsemanticinfoupdater.cpp", "cppsemanticinfoupdater.h",
"cppsourceprocessor.cpp", "cppsourceprocessor.h",
"cpptools.qrc",
"cpptools_global.h",
"cpptoolsconstants.h",
"cpptoolseditorsupport.cpp", "cpptoolseditorsupport.h",
"cpptoolsplugin.cpp", "cpptoolsplugin.h",
"cpptoolsreuse.cpp", "cpptoolsreuse.h",
"cpptoolssettings.cpp", "cpptoolssettings.h",
"cppworkingcopy.cpp", "cppworkingcopy.h",
"doxygengenerator.cpp", "doxygengenerator.h",
"editordocumenthandle.cpp", "editordocumenthandle.h",
"functionutils.cpp", "functionutils.h",
"includeutils.cpp", "includeutils.h",
"indexitem.cpp", "indexitem.h",
"insertionpointlocator.cpp", "insertionpointlocator.h",
"searchsymbols.cpp", "searchsymbols.h",
"semantichighlighter.cpp", "semantichighlighter.h",
"stringtable.cpp", "stringtable.h",
"symbolfinder.cpp", "symbolfinder.h",
"symbolsfindfilter.cpp", "symbolsfindfilter.h",

View File

@@ -52,6 +52,9 @@ public:
QByteArray source(const QString &fileName) const
{ return _elements.value(fileName).first; }
unsigned revision(const QString &fileName) const
{ return _elements.value(fileName).second; }
QPair<QByteArray, unsigned> get(const QString &fileName) const
{ return _elements.value(fileName); }

View File

@@ -27,16 +27,23 @@
**
****************************************************************************/
#include "cpphighlightingsupport.h"
#include "editordocumenthandle.h"
using namespace CppTools;
namespace CppTools {
CppHighlightingSupport::CppHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument)
: m_baseTextDocument(baseTextDocument)
{
Q_ASSERT(baseTextDocument);
}
/*!
\class CppTools::EditorDocumentHandle
CppHighlightingSupport::~CppHighlightingSupport()
\brief The EditorDocumentHandle class provides an interface to an opened
C++ editor document.
*/
EditorDocumentHandle::EditorDocumentHandle()
{
}
EditorDocumentHandle::~EditorDocumentHandle()
{
}
} // namespace CppTools

View File

@@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef EDITORDOCUMENTHANDLE_H
#define EDITORDOCUMENTHANDLE_H
#include "baseeditordocumentprocessor.h"
#include "cpptools_global.h"
namespace CppTools {
class CPPTOOLS_EXPORT EditorDocumentHandle
{
public:
EditorDocumentHandle();
virtual ~EditorDocumentHandle();
// For the Working Copy
virtual QString filePath() const = 0;
virtual QByteArray contents() const = 0;
virtual unsigned revision() const = 0;
// For updating if new project info is set
virtual BaseEditorDocumentProcessor *processor() = 0;
};
} // namespace CppTools
#endif // EDITORDOCUMENTHANDLE_H

View File

@@ -0,0 +1,165 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "semantichighlighter.h"
#include <texteditor/fontsettings.h>
#include <texteditor/syntaxhighlighter.h>
#include <utils/qtcassert.h>
enum { debug = 0 };
using namespace CPlusPlus;
using TextEditor::SemanticHighlighter::incrementalApplyExtraAdditionalFormats;
using TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd;
namespace CppTools {
SemanticHighlighter::SemanticHighlighter(TextEditor::BaseTextDocument *baseTextDocument)
: QObject(baseTextDocument)
, m_baseTextDocument(baseTextDocument)
, m_revision(0)
{
QTC_CHECK(m_baseTextDocument);
connect(baseTextDocument, &TextEditor::BaseTextDocument::fontSettingsChanged,
this, &SemanticHighlighter::onDocumentFontSettingsChanged);
updateFormatMapFromFontSettings();
}
SemanticHighlighter::~SemanticHighlighter()
{
if (m_watcher) {
disconnectWatcher();
m_watcher->cancel();
m_watcher->waitForFinished();
}
}
void SemanticHighlighter::setHighlightingRunner(HighlightingRunner highlightingRunner)
{
m_highlightingRunner = highlightingRunner;
}
void SemanticHighlighter::run()
{
QTC_ASSERT(m_highlightingRunner, return);
if (debug)
qDebug() << "SemanticHighlighter: run()";
if (m_watcher) {
disconnectWatcher();
m_watcher->cancel();
}
m_watcher.reset(new QFutureWatcher<TextEditor::HighlightingResult>);
connectWatcher();
m_revision = documentRevision();
m_watcher->setFuture(m_highlightingRunner());
}
void SemanticHighlighter::onDocumentFontSettingsChanged()
{
updateFormatMapFromFontSettings();
run();
}
void SemanticHighlighter::onHighlighterResultAvailable(int from, int to)
{
if (documentRevision() != m_revision)
return; // outdated
else if (!m_watcher || m_watcher->isCanceled())
return; // aborted
if (debug)
qDebug() << "SemanticHighlighter: onHighlighterResultAvailable()" << from << to;
TextEditor::SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
QTC_ASSERT(highlighter, return);
incrementalApplyExtraAdditionalFormats(highlighter, m_watcher->future(), from, to, m_formatMap);
}
void SemanticHighlighter::onHighlighterFinished()
{
QTC_ASSERT(m_watcher, return);
if (!m_watcher->isCanceled() && documentRevision() == m_revision) {
TextEditor::SyntaxHighlighter *highlighter = m_baseTextDocument->syntaxHighlighter();
QTC_CHECK(highlighter);
if (highlighter) {
if (debug)
qDebug() << "SemanticHighlighter: onHighlighterFinished() - clearing formats";
clearExtraAdditionalFormatsUntilEnd(highlighter, m_watcher->future());
}
}
m_watcher.reset();
}
void SemanticHighlighter::connectWatcher()
{
typedef QFutureWatcher<TextEditor::HighlightingResult> Watcher;
connect(m_watcher.data(), &Watcher::resultsReadyAt,
this, &SemanticHighlighter::onHighlighterResultAvailable);
connect(m_watcher.data(), &Watcher::finished,
this, &SemanticHighlighter::onHighlighterFinished);
}
void SemanticHighlighter::disconnectWatcher()
{
typedef QFutureWatcher<TextEditor::HighlightingResult> Watcher;
disconnect(m_watcher.data(), &Watcher::resultsReadyAt,
this, &SemanticHighlighter::onHighlighterResultAvailable);
disconnect(m_watcher.data(), &Watcher::finished,
this, &SemanticHighlighter::onHighlighterFinished);
}
unsigned SemanticHighlighter::documentRevision() const
{
return m_baseTextDocument->document()->revision();
}
void SemanticHighlighter::updateFormatMapFromFontSettings()
{
const TextEditor::FontSettings &fs = m_baseTextDocument->fontSettings();
m_formatMap[TypeUse] = fs.toTextCharFormat(TextEditor::C_TYPE);
m_formatMap[LocalUse] = fs.toTextCharFormat(TextEditor::C_LOCAL);
m_formatMap[FieldUse] = fs.toTextCharFormat(TextEditor::C_FIELD);
m_formatMap[EnumerationUse] = fs.toTextCharFormat(TextEditor::C_ENUMERATION);
m_formatMap[VirtualMethodUse] = fs.toTextCharFormat(TextEditor::C_VIRTUAL_METHOD);
m_formatMap[LabelUse] = fs.toTextCharFormat(TextEditor::C_LABEL);
m_formatMap[MacroUse] = fs.toTextCharFormat(TextEditor::C_PREPROCESSOR);
m_formatMap[FunctionUse] = fs.toTextCharFormat(TextEditor::C_FUNCTION);
m_formatMap[PseudoKeywordUse] = fs.toTextCharFormat(TextEditor::C_KEYWORD);
m_formatMap[StringUse] = fs.toTextCharFormat(TextEditor::C_STRING);
}
} // namespace CppTools

View File

@@ -27,23 +27,28 @@
**
****************************************************************************/
#ifndef CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
#define CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
#ifndef SEMANTICHIGHLIGHTER_H
#define SEMANTICHIGHLIGHTER_H
#include "cppsemanticinfo.h"
#include "cpptools_global.h"
#include <texteditor/basetextdocument.h>
#include <texteditor/semantichighlighter.h>
#include <cplusplus/CppDocument.h>
#include <QFutureWatcher>
#include <QScopedPointer>
#include <QTextEdit>
#include <QFuture>
namespace TextEditor { class BaseTextDocument; }
#include <functional>
namespace CppTools {
class CPPTOOLS_EXPORT CppHighlightingSupport
class CPPTOOLS_EXPORT SemanticHighlighter : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(SemanticHighlighter)
public:
enum Kind {
Unknown = 0,
@@ -59,27 +64,39 @@ public:
StringUse
};
typedef std::function<QFuture<TextEditor::HighlightingResult> ()> HighlightingRunner;
public:
CppHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument);
virtual ~CppHighlightingSupport() = 0;
explicit SemanticHighlighter(TextEditor::BaseTextDocument *baseTextDocument);
~SemanticHighlighter();
virtual bool requiresSemanticInfo() const = 0;
void setHighlightingRunner(HighlightingRunner highlightingRunner);
virtual bool hightlighterHandlesDiagnostics() const = 0;
virtual bool hightlighterHandlesIfdefedOutBlocks() const = 0;
void run();
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
const CPlusPlus::Document::Ptr &doc,
const CPlusPlus::Snapshot &snapshot) const = 0;
private slots:
void onDocumentFontSettingsChanged();
protected:
TextEditor::BaseTextDocument *baseTextDocument() const
{ return m_baseTextDocument; }
void onHighlighterResultAvailable(int from, int to);
void onHighlighterFinished();
private:
void connectWatcher();
void disconnectWatcher();
unsigned documentRevision() const;
void updateFormatMapFromFontSettings();
private:
TextEditor::BaseTextDocument *m_baseTextDocument;
unsigned m_revision;
QScopedPointer<QFutureWatcher<TextEditor::HighlightingResult>> m_watcher;
QHash<int, QTextCharFormat> m_formatMap;
HighlightingRunner m_highlightingRunner;
};
} // namespace CppTools
#endif // CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H
#endif // SEMANTICHIGHLIGHTER_H