forked from qt-creator/qt-creator
Revert "Introduced a token cache for the C++ editor."
This reverts commit c2393df023
.
This commit is contained in:
@@ -27,48 +27,33 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
#include "BackwardsScanner.h"
|
#include "BackwardsScanner.h"
|
||||||
#include "TokenCache.h"
|
|
||||||
#include <Token.h>
|
#include <Token.h>
|
||||||
#include <QtGui/QTextCursor>
|
#include <QtGui/QTextCursor>
|
||||||
#include <QTextDocument>
|
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
BackwardsScanner::BackwardsScanner(TokenCache *tokenCache, const QTextCursor &cursor, int maxBlockCount, const QString &suffix)
|
BackwardsScanner::BackwardsScanner(const QTextCursor &cursor, const QString &suffix, int maxBlockCount)
|
||||||
: _tokenCache(tokenCache)
|
: _offset(0)
|
||||||
, _offset(0)
|
|
||||||
, _blocksTokenized(0)
|
, _blocksTokenized(0)
|
||||||
, _block(cursor.block())
|
, _block(cursor.block())
|
||||||
, _maxBlockCount(maxBlockCount)
|
, _maxBlockCount(maxBlockCount)
|
||||||
{
|
{
|
||||||
int pos = cursor.position() - cursor.block().position();
|
_tokenize.setQtMocRunEnabled(true);
|
||||||
_text = _block.text().left(pos);
|
_tokenize.setSkipComments(true);
|
||||||
|
_tokenize.setObjCEnabled(true);
|
||||||
if (suffix.isEmpty()) {
|
_text = _block.text().left(cursor.position() - cursor.block().position());
|
||||||
_tokens.append(tokenCache->tokensForBlock(_block));
|
|
||||||
int last = -1;
|
|
||||||
for (int i = _tokens.size() - 1; i >= 0; --i) {
|
|
||||||
if (_tokens.at(i).begin() < pos) {
|
|
||||||
last = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = _tokens.size() - 1; i > last && i >= 0; --i)
|
|
||||||
_tokens.removeAt(i);
|
|
||||||
} else {
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setQtMocRunEnabled(true);
|
|
||||||
tokenize.setSkipComments(true);
|
|
||||||
tokenize.setObjCEnabled(true);
|
|
||||||
|
|
||||||
|
if (! suffix.isEmpty())
|
||||||
_text += suffix;
|
_text += suffix;
|
||||||
|
|
||||||
_tokens.append(tokenize(_text, TokenCache::previousBlockState(_block)));
|
_tokens.append(_tokenize(_text, previousBlockState(_block)));
|
||||||
}
|
|
||||||
|
|
||||||
_startToken = _tokens.size();
|
_startToken = _tokens.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BackwardsScanner::state() const
|
||||||
|
{ return _tokenize.state(); }
|
||||||
|
|
||||||
SimpleToken BackwardsScanner::LA(int index) const
|
SimpleToken BackwardsScanner::LA(int index) const
|
||||||
{ return const_cast<BackwardsScanner *>(this)->fetchToken(_startToken - index); }
|
{ return const_cast<BackwardsScanner *>(this)->fetchToken(_startToken - index); }
|
||||||
|
|
||||||
@@ -98,7 +83,7 @@ const SimpleToken &BackwardsScanner::fetchToken(int tokenIndex)
|
|||||||
adaptedTokens.append(t);
|
adaptedTokens.append(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
_tokens = _tokenCache->tokensForBlock(_block);
|
_tokens = _tokenize(blockText, previousBlockState(_block));
|
||||||
_offset += _tokens.size();
|
_offset += _tokens.size();
|
||||||
_tokens += adaptedTokens;
|
_tokens += adaptedTokens;
|
||||||
}
|
}
|
||||||
@@ -134,6 +119,20 @@ QStringRef BackwardsScanner::textRef(int index) const
|
|||||||
return _text.midRef(firstToken.begin(), firstToken.length());
|
return _text.midRef(firstToken.begin(), firstToken.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BackwardsScanner::previousBlockState(const QTextBlock &block)
|
||||||
|
{
|
||||||
|
const QTextBlock prevBlock = block.previous();
|
||||||
|
|
||||||
|
if (prevBlock.isValid()) {
|
||||||
|
int state = prevBlock.userState();
|
||||||
|
|
||||||
|
if (state != -1)
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int BackwardsScanner::size() const
|
int BackwardsScanner::size() const
|
||||||
{
|
{
|
||||||
return _tokens.size();
|
return _tokens.size();
|
||||||
|
@@ -36,18 +36,16 @@
|
|||||||
|
|
||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
|
|
||||||
class TokenCache;
|
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT BackwardsScanner
|
class CPLUSPLUS_EXPORT BackwardsScanner
|
||||||
{
|
{
|
||||||
enum { MAX_BLOCK_COUNT = 10 };
|
enum { MAX_BLOCK_COUNT = 10 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BackwardsScanner(TokenCache *cache,
|
BackwardsScanner(const QTextCursor &cursor,
|
||||||
const QTextCursor &cursor,
|
const QString &suffix = QString(),
|
||||||
int maxBlockCount = MAX_BLOCK_COUNT,
|
int maxBlockCount = MAX_BLOCK_COUNT);
|
||||||
const QString &suffix = QString());
|
|
||||||
|
|
||||||
|
int state() const;
|
||||||
int startToken() const;
|
int startToken() const;
|
||||||
|
|
||||||
int startPosition() const;
|
int startPosition() const;
|
||||||
@@ -69,18 +67,20 @@ public:
|
|||||||
int startOfMatchingBrace(int index) const;
|
int startOfMatchingBrace(int index) const;
|
||||||
int startOfBlock(int index) const;
|
int startOfBlock(int index) const;
|
||||||
|
|
||||||
|
static int previousBlockState(const QTextBlock &block);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const SimpleToken &fetchToken(int tokenIndex);
|
const SimpleToken &fetchToken(int tokenIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TokenCache *_tokenCache;
|
|
||||||
QList<SimpleToken> _tokens;
|
QList<SimpleToken> _tokens;
|
||||||
int _offset;
|
int _offset;
|
||||||
int _blocksTokenized;
|
int _blocksTokenized;
|
||||||
QTextBlock _block;
|
QTextBlock _block;
|
||||||
QString _text;
|
QString _text;
|
||||||
|
SimpleLexer _tokenize;
|
||||||
int _maxBlockCount;
|
int _maxBlockCount;
|
||||||
int _startToken;
|
int _startToken;
|
||||||
};
|
};
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
#include "ExpressionUnderCursor.h"
|
#include "ExpressionUnderCursor.h"
|
||||||
#include "SimpleLexer.h"
|
#include "SimpleLexer.h"
|
||||||
#include "BackwardsScanner.h"
|
#include "BackwardsScanner.h"
|
||||||
#include "TokenCache.h"
|
|
||||||
#include <Token.h>
|
#include <Token.h>
|
||||||
|
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
@@ -38,8 +37,8 @@
|
|||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
ExpressionUnderCursor::ExpressionUnderCursor(TokenCache *tokenCache)
|
ExpressionUnderCursor::ExpressionUnderCursor()
|
||||||
: _tokenCache(tokenCache), _jumpedComma(false)
|
: _jumpedComma(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ExpressionUnderCursor::~ExpressionUnderCursor()
|
ExpressionUnderCursor::~ExpressionUnderCursor()
|
||||||
@@ -219,7 +218,7 @@ bool ExpressionUnderCursor::isAccessToken(const SimpleToken &tk)
|
|||||||
|
|
||||||
QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
|
QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
BackwardsScanner scanner(_tokenCache, cursor);
|
BackwardsScanner scanner(cursor);
|
||||||
|
|
||||||
_jumpedComma = false;
|
_jumpedComma = false;
|
||||||
|
|
||||||
@@ -233,7 +232,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
|
|||||||
|
|
||||||
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
|
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
BackwardsScanner scanner(_tokenCache, cursor);
|
BackwardsScanner scanner(cursor);
|
||||||
|
|
||||||
int index = scanner.startToken();
|
int index = scanner.startToken();
|
||||||
|
|
||||||
|
@@ -43,12 +43,11 @@ namespace CPlusPlus {
|
|||||||
|
|
||||||
class BackwardsScanner;
|
class BackwardsScanner;
|
||||||
class SimpleToken;
|
class SimpleToken;
|
||||||
class TokenCache;
|
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT ExpressionUnderCursor
|
class CPLUSPLUS_EXPORT ExpressionUnderCursor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExpressionUnderCursor(TokenCache *tokenCache);
|
ExpressionUnderCursor();
|
||||||
~ExpressionUnderCursor();
|
~ExpressionUnderCursor();
|
||||||
|
|
||||||
QString operator()(const QTextCursor &cursor);
|
QString operator()(const QTextCursor &cursor);
|
||||||
@@ -60,7 +59,6 @@ private:
|
|||||||
bool isAccessToken(const SimpleToken &tk);
|
bool isAccessToken(const SimpleToken &tk);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TokenCache *_tokenCache;
|
|
||||||
bool _jumpedComma;
|
bool _jumpedComma;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -28,7 +28,6 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
#include "MatchingText.h"
|
#include "MatchingText.h"
|
||||||
#include "BackwardsScanner.h"
|
#include "BackwardsScanner.h"
|
||||||
#include "TokenCache.h"
|
|
||||||
|
|
||||||
#include <Token.h>
|
#include <Token.h>
|
||||||
|
|
||||||
@@ -76,8 +75,7 @@ static bool isCompleteCharLiteral(const BackwardsScanner &tk, int index)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MatchingText::MatchingText(TokenCache *tokenCache)
|
MatchingText::MatchingText()
|
||||||
: _tokenCache(tokenCache)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool MatchingText::shouldInsertMatchingText(const QTextCursor &tc)
|
bool MatchingText::shouldInsertMatchingText(const QTextCursor &tc)
|
||||||
@@ -153,7 +151,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
|||||||
if (text.isEmpty() || !shouldInsertMatchingText(la))
|
if (text.isEmpty() || !shouldInsertMatchingText(la))
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
BackwardsScanner tk(_tokenCache, tc, MAX_NUM_LINES, textToProcess.left(*skippedChars));
|
BackwardsScanner tk(tc, textToProcess.left(*skippedChars), MAX_NUM_LINES);
|
||||||
const int startToken = tk.startToken();
|
const int startToken = tk.startToken();
|
||||||
int index = startToken;
|
int index = startToken;
|
||||||
|
|
||||||
@@ -213,7 +211,7 @@ bool MatchingText::shouldInsertNewline(const QTextCursor &tc) const
|
|||||||
|
|
||||||
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
|
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
|
||||||
{
|
{
|
||||||
BackwardsScanner tk(_tokenCache, tc, MAX_NUM_LINES);
|
BackwardsScanner tk(tc, QString(), MAX_NUM_LINES);
|
||||||
int index = tk.startToken();
|
int index = tk.startToken();
|
||||||
|
|
||||||
if (tk[index - 1].isNot(T_LBRACE))
|
if (tk[index - 1].isNot(T_LBRACE))
|
||||||
|
@@ -35,12 +35,11 @@
|
|||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
|
|
||||||
class BackwardsScanner;
|
class BackwardsScanner;
|
||||||
class TokenCache;
|
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT MatchingText
|
class CPLUSPLUS_EXPORT MatchingText
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MatchingText(TokenCache *tokenCache);
|
MatchingText();
|
||||||
|
|
||||||
static bool shouldInsertMatchingText(const QTextCursor &tc);
|
static bool shouldInsertMatchingText(const QTextCursor &tc);
|
||||||
static bool shouldInsertMatchingText(const QChar &lookAhead);
|
static bool shouldInsertMatchingText(const QChar &lookAhead);
|
||||||
@@ -51,8 +50,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool shouldInsertNewline(const QTextCursor &tc) const;
|
bool shouldInsertNewline(const QTextCursor &tc) const;
|
||||||
|
|
||||||
TokenCache *_tokenCache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace CPlusPlus
|
} // end of namespace CPlusPlus
|
||||||
|
@@ -1,64 +0,0 @@
|
|||||||
#include "SimpleLexer.h"
|
|
||||||
#include "TokenCache.h"
|
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
|
||||||
|
|
||||||
TokenCache::TokenCache()
|
|
||||||
: m_doc(0)
|
|
||||||
, m_revision(-1)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void TokenCache::setDocument(QTextDocument *doc)
|
|
||||||
{
|
|
||||||
m_doc = doc;
|
|
||||||
m_revision = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<SimpleToken> TokenCache::tokensForBlock(const QTextBlock &block) const
|
|
||||||
{
|
|
||||||
Q_ASSERT(m_doc);
|
|
||||||
|
|
||||||
const int documentRevision = m_doc->revision();
|
|
||||||
|
|
||||||
if (documentRevision != m_revision) {
|
|
||||||
m_tokensByBlock.clear();
|
|
||||||
m_revision = documentRevision;
|
|
||||||
// qDebug() << "** revision changed to" << documentRevision;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int blockNr = block.blockNumber();
|
|
||||||
|
|
||||||
if (m_tokensByBlock.contains(blockNr)) {
|
|
||||||
// qDebug()<<"Cache hit on line" << line;
|
|
||||||
return m_tokensByBlock.value(blockNr);
|
|
||||||
} else {
|
|
||||||
// qDebug()<<"Cache miss on line" << line;
|
|
||||||
|
|
||||||
SimpleLexer tokenize;
|
|
||||||
tokenize.setObjCEnabled(true);
|
|
||||||
tokenize.setQtMocRunEnabled(true);
|
|
||||||
tokenize.setSkipComments(false);
|
|
||||||
|
|
||||||
const int prevState = previousBlockState(block);
|
|
||||||
QList<SimpleToken> tokens = tokenize(block.text(), prevState);
|
|
||||||
m_tokensByBlock.insert(blockNr, tokens);
|
|
||||||
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int TokenCache::previousBlockState(const QTextBlock &block)
|
|
||||||
{
|
|
||||||
const QTextBlock prevBlock = block.previous();
|
|
||||||
|
|
||||||
if (prevBlock.isValid()) {
|
|
||||||
int state = prevBlock.userState();
|
|
||||||
|
|
||||||
if (state != -1)
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
#ifndef TOKENCACHE_H
|
|
||||||
#define TOKENCACHE_H
|
|
||||||
|
|
||||||
#include <CPlusPlusForwardDeclarations.h>
|
|
||||||
#include <cplusplus/SimpleLexer.h>
|
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
|
||||||
#include <QtCore/QList>
|
|
||||||
|
|
||||||
#include <QtGui/QTextBlock>
|
|
||||||
#include <QtGui/QTextDocument>
|
|
||||||
|
|
||||||
namespace CPlusPlus {
|
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT TokenCache
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TokenCache();
|
|
||||||
|
|
||||||
void setDocument(QTextDocument *doc);
|
|
||||||
|
|
||||||
QList<CPlusPlus::SimpleToken> tokensForBlock(const QTextBlock &block) const;
|
|
||||||
|
|
||||||
static int previousBlockState(const QTextBlock &block);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QTextDocument *m_doc;
|
|
||||||
|
|
||||||
mutable int m_revision;
|
|
||||||
mutable QHash<int, QList<CPlusPlus::SimpleToken> > m_tokensByBlock;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace CPlusPlus
|
|
||||||
|
|
||||||
#endif // TOKENCACHE_H
|
|
@@ -28,14 +28,12 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "TokenUnderCursor.h"
|
#include "TokenUnderCursor.h"
|
||||||
#include "TokenCache.h"
|
#include "BackwardsScanner.h"
|
||||||
#include "TokenCache.h"
|
|
||||||
#include <Token.h>
|
#include <Token.h>
|
||||||
|
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <QTextDocument>
|
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
|
||||||
@@ -45,13 +43,17 @@ TokenUnderCursor::TokenUnderCursor()
|
|||||||
TokenUnderCursor::~TokenUnderCursor()
|
TokenUnderCursor::~TokenUnderCursor()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
SimpleToken TokenUnderCursor::operator()(TokenCache *cache, const QTextCursor &cursor, QTextBlock *b)
|
SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *b)
|
||||||
{
|
{
|
||||||
|
SimpleLexer tokenize;
|
||||||
|
tokenize.setObjCEnabled(true);
|
||||||
|
tokenize.setSkipComments(false);
|
||||||
|
|
||||||
QTextBlock block = cursor.block();
|
QTextBlock block = cursor.block();
|
||||||
int column = cursor.position() - cursor.block().position();
|
int column = cursor.position() - cursor.block().position();
|
||||||
|
|
||||||
_text = block.text();
|
_text = block.text();
|
||||||
_tokens = cache->tokensForBlock(block);
|
_tokens = tokenize(_text, BackwardsScanner::previousBlockState(block));
|
||||||
for (int index = _tokens.size() - 1; index != -1; --index) {
|
for (int index = _tokens.size() - 1; index != -1; --index) {
|
||||||
const SimpleToken &tk = _tokens.at(index);
|
const SimpleToken &tk = _tokens.at(index);
|
||||||
if (tk.position() < column) {
|
if (tk.position() < column) {
|
||||||
|
@@ -40,15 +40,13 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
|
|
||||||
class TokenCache;
|
|
||||||
|
|
||||||
class CPLUSPLUS_EXPORT TokenUnderCursor
|
class CPLUSPLUS_EXPORT TokenUnderCursor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TokenUnderCursor();
|
TokenUnderCursor();
|
||||||
~TokenUnderCursor();
|
~TokenUnderCursor();
|
||||||
|
|
||||||
SimpleToken operator()(TokenCache *cache, const QTextCursor &cursor, QTextBlock *block = 0);
|
SimpleToken operator()(const QTextCursor &cursor, QTextBlock *block = 0);
|
||||||
|
|
||||||
const QList<SimpleToken> &tokens() const
|
const QList<SimpleToken> &tokens() const
|
||||||
{ return _tokens; }
|
{ return _tokens; }
|
||||||
|
@@ -15,8 +15,7 @@ HEADERS += \
|
|||||||
$$PWD/TokenUnderCursor.h \
|
$$PWD/TokenUnderCursor.h \
|
||||||
$$PWD/BackwardsScanner.h \
|
$$PWD/BackwardsScanner.h \
|
||||||
$$PWD/MatchingText.h \
|
$$PWD/MatchingText.h \
|
||||||
$$PWD/OverviewModel.h \
|
$$PWD/OverviewModel.h
|
||||||
$$PWD/TokenCache.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/Icons.cpp \
|
$$PWD/Icons.cpp \
|
||||||
@@ -24,8 +23,7 @@ SOURCES += \
|
|||||||
$$PWD/TokenUnderCursor.cpp \
|
$$PWD/TokenUnderCursor.cpp \
|
||||||
$$PWD/BackwardsScanner.cpp \
|
$$PWD/BackwardsScanner.cpp \
|
||||||
$$PWD/MatchingText.cpp \
|
$$PWD/MatchingText.cpp \
|
||||||
$$PWD/OverviewModel.cpp \
|
$$PWD/OverviewModel.cpp
|
||||||
$$PWD/TokenCache.cpp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
@@ -56,7 +56,6 @@
|
|||||||
#include <cplusplus/BackwardsScanner.h>
|
#include <cplusplus/BackwardsScanner.h>
|
||||||
#include <cplusplus/FastPreprocessor.h>
|
#include <cplusplus/FastPreprocessor.h>
|
||||||
#include <cplusplus/CheckUndefinedSymbols.h>
|
#include <cplusplus/CheckUndefinedSymbols.h>
|
||||||
#include <cplusplus/TokenCache.h>
|
|
||||||
|
|
||||||
#include <cpptools/cppmodelmanagerinterface.h>
|
#include <cpptools/cppmodelmanagerinterface.h>
|
||||||
|
|
||||||
@@ -535,7 +534,7 @@ struct FindCanonicalSymbol
|
|||||||
SemanticInfo info;
|
SemanticInfo info;
|
||||||
|
|
||||||
FindCanonicalSymbol(CPPEditor *editor, const SemanticInfo &info)
|
FindCanonicalSymbol(CPPEditor *editor, const SemanticInfo &info)
|
||||||
: editor(editor), expressionUnderCursor(editor->tokenCache()), info(info)
|
: editor(editor), info(info)
|
||||||
{
|
{
|
||||||
typeOfExpression.init(info.doc, info.snapshot);
|
typeOfExpression.init(info.doc, info.snapshot);
|
||||||
}
|
}
|
||||||
@@ -773,11 +772,6 @@ void CPPEditor::cut()
|
|||||||
finishRename();
|
finishRename();
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenCache *CPPEditor::tokenCache() const
|
|
||||||
{
|
|
||||||
return m_modelManager->tokenCache(editableInterface());
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPPEditor::startRename()
|
void CPPEditor::startRename()
|
||||||
{
|
{
|
||||||
m_inRenameChanged = false;
|
m_inRenameChanged = false;
|
||||||
@@ -1257,7 +1251,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
SimpleLexer tokenize;
|
SimpleLexer tokenize;
|
||||||
tokenize.setQtMocRunEnabled(true);
|
tokenize.setQtMocRunEnabled(true);
|
||||||
const QString blockText = cursor.block().text();
|
const QString blockText = cursor.block().text();
|
||||||
const QList<SimpleToken> tokens = tokenize(blockText, TokenCache::previousBlockState(cursor.block()));
|
const QList<SimpleToken> tokens = tokenize(blockText, BackwardsScanner::previousBlockState(cursor.block()));
|
||||||
|
|
||||||
bool recognizedQtMethod = false;
|
bool recognizedQtMethod = false;
|
||||||
|
|
||||||
@@ -1307,7 +1301,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
static TokenUnderCursor tokenUnderCursor;
|
static TokenUnderCursor tokenUnderCursor;
|
||||||
|
|
||||||
QTextBlock block;
|
QTextBlock block;
|
||||||
const SimpleToken tk = tokenUnderCursor(tokenCache(), tc, &block);
|
const SimpleToken tk = tokenUnderCursor(tc, &block);
|
||||||
|
|
||||||
beginOfToken = block.position() + tk.begin();
|
beginOfToken = block.position() + tk.begin();
|
||||||
endOfToken = block.position() + tk.end();
|
endOfToken = block.position() + tk.end();
|
||||||
@@ -1337,7 +1331,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
return link;
|
return link;
|
||||||
|
|
||||||
// Evaluate the type of the expression under the cursor
|
// Evaluate the type of the expression under the cursor
|
||||||
ExpressionUnderCursor expressionUnderCursor(tokenCache());
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
const QString expression = expressionUnderCursor(tc);
|
const QString expression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
@@ -1436,13 +1430,13 @@ bool CPPEditor::isElectricCharacter(const QChar &ch) const
|
|||||||
QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
||||||
const QChar &la, int *skippedChars) const
|
const QChar &la, int *skippedChars) const
|
||||||
{
|
{
|
||||||
MatchingText m(tokenCache());
|
MatchingText m;
|
||||||
return m.insertMatchingBrace(tc, text, la, skippedChars);
|
return m.insertMatchingBrace(tc, text, la, skippedChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CPPEditor::insertParagraphSeparator(const QTextCursor &tc) const
|
QString CPPEditor::insertParagraphSeparator(const QTextCursor &tc) const
|
||||||
{
|
{
|
||||||
MatchingText m(tokenCache());
|
MatchingText m;
|
||||||
return m.insertParagraphSeparator(tc);
|
return m.insertParagraphSeparator(tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1466,7 +1460,7 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
|||||||
bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
||||||
const SimpleToken tk = tokenUnderCursor(tokenCache(), cursor);
|
const SimpleToken tk = tokenUnderCursor(cursor);
|
||||||
|
|
||||||
if (tk.isComment()) {
|
if (tk.isComment()) {
|
||||||
const int pos = cursor.selectionEnd() - cursor.block().position();
|
const int pos = cursor.selectionEnd() - cursor.block().position();
|
||||||
@@ -1521,7 +1515,7 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
|
|||||||
|
|
||||||
const TabSettings &ts = tabSettings();
|
const TabSettings &ts = tabSettings();
|
||||||
|
|
||||||
BackwardsScanner tk(tokenCache(), tc, 400);
|
BackwardsScanner tk(tc, QString(), 400);
|
||||||
const int tokenCount = tk.startToken();
|
const int tokenCount = tk.startToken();
|
||||||
|
|
||||||
if (tokenCount != 0) {
|
if (tokenCount != 0) {
|
||||||
|
@@ -48,7 +48,6 @@ QT_END_NAMESPACE
|
|||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
class OverviewModel;
|
class OverviewModel;
|
||||||
class Symbol;
|
class Symbol;
|
||||||
class TokenCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
@@ -199,8 +198,6 @@ public:
|
|||||||
virtual void paste(); // reimplemented from BaseTextEditor
|
virtual void paste(); // reimplemented from BaseTextEditor
|
||||||
virtual void cut(); // reimplemented from BaseTextEditor
|
virtual void cut(); // reimplemented from BaseTextEditor
|
||||||
|
|
||||||
CPlusPlus::TokenCache *tokenCache() const;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
virtual void setFontSettings(const TextEditor::FontSettings &);
|
virtual void setFontSettings(const TextEditor::FontSettings &);
|
||||||
void setSortedMethodOverview(bool sort);
|
void setSortedMethodOverview(bool sort);
|
||||||
|
@@ -62,7 +62,6 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
tokenize.setObjCEnabled(false);
|
tokenize.setObjCEnabled(false);
|
||||||
|
|
||||||
int initialState = state;
|
int initialState = state;
|
||||||
// qDebug() << currentBlock().document()->revision()<<"CppHighlighter::highlightBlock for block#" << currentBlock().blockNumber();
|
|
||||||
const QList<SimpleToken> tokens = tokenize(text, initialState);
|
const QList<SimpleToken> tokens = tokenize(text, initialState);
|
||||||
state = tokenize.state(); // refresh the state
|
state = tokenize.state(); // refresh the state
|
||||||
|
|
||||||
|
@@ -254,7 +254,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the expression's code
|
// Fetch the expression's code
|
||||||
ExpressionUnderCursor expressionUnderCursor(m_modelManager->tokenCache(editor));
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
const QString expression = expressionUnderCursor(tc);
|
const QString expression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
const QList<LookupItem> types = typeOfExpression(expression, scope);
|
const QList<LookupItem> types = typeOfExpression(expression, scope);
|
||||||
|
@@ -37,10 +37,6 @@ class QHelpEngineCore;
|
|||||||
class QPoint;
|
class QPoint;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace CPlusPlus {
|
|
||||||
class TokenCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IEditor;
|
class IEditor;
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,7 @@
|
|||||||
#include <utils/faketooltip.h>
|
#include <utils/faketooltip.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QMap>
|
#include <QtCore/QMap>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtGui/QAction>
|
#include <QtGui/QAction>
|
||||||
@@ -453,8 +454,7 @@ QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
|
|||||||
/*
|
/*
|
||||||
Searches backwards for an access operator.
|
Searches backwards for an access operator.
|
||||||
*/
|
*/
|
||||||
static int startOfOperator(TokenCache *tokenCache,
|
static int startOfOperator(TextEditor::ITextEditable *editor,
|
||||||
TextEditor::ITextEditable *editor,
|
|
||||||
int pos, unsigned *kind,
|
int pos, unsigned *kind,
|
||||||
bool wantFunctionCall)
|
bool wantFunctionCall)
|
||||||
{
|
{
|
||||||
@@ -547,7 +547,7 @@ static int startOfOperator(TokenCache *tokenCache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (completionKind == T_COMMA) {
|
if (completionKind == T_COMMA) {
|
||||||
ExpressionUnderCursor expressionUnderCursor(tokenCache);
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
if (expressionUnderCursor.startOfFunctionCall(tc) == -1) {
|
if (expressionUnderCursor.startOfFunctionCall(tc) == -1) {
|
||||||
completionKind = T_EOF_SYMBOL;
|
completionKind = T_EOF_SYMBOL;
|
||||||
start = pos;
|
start = pos;
|
||||||
@@ -555,7 +555,7 @@ static int startOfOperator(TokenCache *tokenCache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
static CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
||||||
const SimpleToken tk = tokenUnderCursor(tokenCache, tc);
|
const SimpleToken tk = tokenUnderCursor(tc);
|
||||||
|
|
||||||
if (completionKind == T_DOXY_COMMENT && !(tk.is(T_DOXY_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))) {
|
if (completionKind == T_DOXY_COMMENT && !(tk.is(T_DOXY_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))) {
|
||||||
completionKind = T_EOF_SYMBOL;
|
completionKind = T_EOF_SYMBOL;
|
||||||
@@ -634,10 +634,9 @@ int CppCodeCompletion::startPosition() const
|
|||||||
bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
|
||||||
{
|
{
|
||||||
const int pos = editor->position();
|
const int pos = editor->position();
|
||||||
TokenCache *tokenCache = m_manager->tokenCache(editor);
|
|
||||||
unsigned token = T_EOF_SYMBOL;
|
unsigned token = T_EOF_SYMBOL;
|
||||||
|
|
||||||
if (startOfOperator(tokenCache, editor, pos, &token, /*want function call=*/ true) != pos) {
|
if (startOfOperator(editor, pos, &token, /*want function call=*/ true) != pos) {
|
||||||
if (token == T_POUND) {
|
if (token == T_POUND) {
|
||||||
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget())) {
|
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget())) {
|
||||||
QTextCursor tc(edit->document());
|
QTextCursor tc(edit->document());
|
||||||
@@ -685,8 +684,7 @@ int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
|
|||||||
while (editor->characterAt(endOfOperator - 1).isSpace())
|
while (editor->characterAt(endOfOperator - 1).isSpace())
|
||||||
--endOfOperator;
|
--endOfOperator;
|
||||||
|
|
||||||
TokenCache *tokenCache = m_manager->tokenCache(editor);
|
int endOfExpression = startOfOperator(editor, endOfOperator,
|
||||||
int endOfExpression = startOfOperator(tokenCache, editor, endOfOperator,
|
|
||||||
&m_completionOperator,
|
&m_completionOperator,
|
||||||
/*want function call =*/ true);
|
/*want function call =*/ true);
|
||||||
|
|
||||||
@@ -727,7 +725,7 @@ int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
|
|||||||
return m_startPosition;
|
return m_startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionUnderCursor expressionUnderCursor(m_manager->tokenCache(editor));
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
QTextCursor tc(edit->document());
|
QTextCursor tc(edit->document());
|
||||||
|
|
||||||
if (m_completionOperator == T_COMMA) {
|
if (m_completionOperator == T_COMMA) {
|
||||||
@@ -802,13 +800,13 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (debug)
|
if (debug)
|
||||||
// qDebug() << "scope:" << scope->owner()->fileName() << scope->owner()->line() << scope->owner()->column();
|
qDebug() << "scope:" << scope->owner()->fileName() << scope->owner()->line() << scope->owner()->column();
|
||||||
|
|
||||||
QList<LookupItem> results = typeOfExpression(expression, scope, TypeOfExpression::Preprocess);
|
QList<LookupItem> results = typeOfExpression(expression, scope, TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
// if (debug)
|
if (debug)
|
||||||
// qDebug() << "got:" << results.size() << "results";
|
qDebug() << "got:" << results.size() << "results";
|
||||||
|
|
||||||
if (results.isEmpty()) {
|
if (results.isEmpty()) {
|
||||||
if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
||||||
@@ -830,8 +828,7 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
|
|||||||
QTextCursor tc(edit->document());
|
QTextCursor tc(edit->document());
|
||||||
tc.setPosition(index);
|
tc.setPosition(index);
|
||||||
|
|
||||||
TokenCache *tokenCache = m_manager->tokenCache(edit->editableInterface());
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
ExpressionUnderCursor expressionUnderCursor(tokenCache);
|
|
||||||
const QString baseExpression = expressionUnderCursor(tc);
|
const QString baseExpression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
// Resolve the type of this expression
|
// Resolve the type of this expression
|
||||||
@@ -1087,8 +1084,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
|
|||||||
|
|
||||||
QTextCursor tc(edit->document());
|
QTextCursor tc(edit->document());
|
||||||
tc.setPosition(endOfExpression);
|
tc.setPosition(endOfExpression);
|
||||||
TokenCache *tokenCache = m_manager->tokenCache(m_editor);
|
BackwardsScanner bs(tc);
|
||||||
BackwardsScanner bs(tokenCache, tc);
|
|
||||||
const int startToken = bs.startToken();
|
const int startToken = bs.startToken();
|
||||||
const int lineStartToken = bs.startOfLine(startToken);
|
const int lineStartToken = bs.startOfLine(startToken);
|
||||||
// make sure the required tokens are actually available
|
// make sure the required tokens are actually available
|
||||||
@@ -1147,8 +1143,8 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults)
|
|||||||
{
|
{
|
||||||
const LookupContext &context = typeOfExpression.context();
|
const LookupContext &context = typeOfExpression.context();
|
||||||
|
|
||||||
// if (debug)
|
if (debug)
|
||||||
// qDebug() << Q_FUNC_INFO << __LINE__;
|
qDebug() << Q_FUNC_INFO << __LINE__;
|
||||||
|
|
||||||
if (baseResults.isEmpty())
|
if (baseResults.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@@ -1160,8 +1156,8 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults)
|
|||||||
if (ClassOrNamespace *binding = resolveExpression.baseExpression(baseResults,
|
if (ClassOrNamespace *binding = resolveExpression.baseExpression(baseResults,
|
||||||
m_completionOperator,
|
m_completionOperator,
|
||||||
&replacedDotOperator)) {
|
&replacedDotOperator)) {
|
||||||
// if (debug)
|
if (debug)
|
||||||
// qDebug() << "cool we got a binding for the base expression";
|
qDebug() << "cool we got a binding for the base expression";
|
||||||
|
|
||||||
if (replacedDotOperator && binding) {
|
if (replacedDotOperator && binding) {
|
||||||
// Replace . with ->
|
// Replace . with ->
|
||||||
@@ -1177,10 +1173,10 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults)
|
|||||||
return ! m_completions.isEmpty();
|
return ! m_completions.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (debug) {
|
if (debug) {
|
||||||
// Overview oo;
|
Overview oo;
|
||||||
// qDebug() << "hmm, got:" << oo(baseResults.first().type());
|
qDebug() << "hmm, got:" << oo(baseResults.first().type());
|
||||||
// }
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -962,9 +962,6 @@ bool CppModelManager::isCppEditor(Core::IEditor *editor) const
|
|||||||
return editor->context().contains(uid);
|
return editor->context().contains(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenCache *CppModelManager::tokenCache(TextEditor::ITextEditor *editor) const
|
|
||||||
{ return editorSupport(editor)->tokenCache(); }
|
|
||||||
|
|
||||||
void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
|
void CppModelManager::emitDocumentUpdated(Document::Ptr doc)
|
||||||
{ emit documentUpdated(doc); }
|
{ emit documentUpdated(doc); }
|
||||||
|
|
||||||
|
@@ -108,8 +108,6 @@ public:
|
|||||||
CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const
|
CppEditorSupport *editorSupport(TextEditor::ITextEditor *editor) const
|
||||||
{ return m_editorSupport.value(editor); }
|
{ return m_editorSupport.value(editor); }
|
||||||
|
|
||||||
virtual CPlusPlus::TokenCache *tokenCache(TextEditor::ITextEditor *editor) const;
|
|
||||||
|
|
||||||
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
|
|
||||||
void stopEditorSelectionsUpdate()
|
void stopEditorSelectionsUpdate()
|
||||||
|
@@ -40,25 +40,16 @@
|
|||||||
|
|
||||||
namespace CPlusPlus {
|
namespace CPlusPlus {
|
||||||
class LookupContext;
|
class LookupContext;
|
||||||
class TokenCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class Project;
|
class Project;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace TextEditor {
|
|
||||||
class ITextEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
class AbstractEditorSupport;
|
class AbstractEditorSupport;
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
class CppEditorSupport;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
|
class CPPTOOLS_EXPORT CppModelManagerInterface : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -139,8 +130,6 @@ public:
|
|||||||
|
|
||||||
virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0;
|
virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0;
|
||||||
|
|
||||||
virtual CPlusPlus::TokenCache *tokenCache(TextEditor::ITextEditor *editor) const = 0;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void documentUpdated(CPlusPlus::Document::Ptr doc);
|
void documentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
|
|
||||||
|
@@ -67,12 +67,8 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
|
|||||||
{
|
{
|
||||||
_textEditor = textEditor;
|
_textEditor = textEditor;
|
||||||
|
|
||||||
if (_textEditor) {
|
if (! _textEditor)
|
||||||
if (TextEditor::BaseTextEditor *ed = qobject_cast<TextEditor::BaseTextEditor *>(_textEditor->widget()))
|
|
||||||
_tokenCache.setDocument(ed->document());
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
connect(_textEditor, SIGNAL(contentsChanged()), this, SIGNAL(contentsChanged()));
|
connect(_textEditor, SIGNAL(contentsChanged()), this, SIGNAL(contentsChanged()));
|
||||||
connect(this, SIGNAL(contentsChanged()), this, SLOT(updateDocument()));
|
connect(this, SIGNAL(contentsChanged()), this, SLOT(updateDocument()));
|
||||||
@@ -100,11 +96,6 @@ unsigned CppEditorSupport::editorRevision() const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenCache *CppEditorSupport::tokenCache()
|
|
||||||
{
|
|
||||||
return &_tokenCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CppEditorSupport::updateDocumentInterval() const
|
int CppEditorSupport::updateDocumentInterval() const
|
||||||
{ return _updateDocumentInterval; }
|
{ return _updateDocumentInterval; }
|
||||||
|
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <cplusplus/TokenCache.h>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTimer;
|
class QTimer;
|
||||||
@@ -73,8 +72,6 @@ public:
|
|||||||
QString contents();
|
QString contents();
|
||||||
unsigned editorRevision() const;
|
unsigned editorRevision() const;
|
||||||
|
|
||||||
CPlusPlus::TokenCache *tokenCache();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void contentsChanged();
|
void contentsChanged();
|
||||||
|
|
||||||
@@ -92,7 +89,6 @@ private:
|
|||||||
QFuture<void> _documentParser;
|
QFuture<void> _documentParser;
|
||||||
QString _cachedContents;
|
QString _cachedContents;
|
||||||
unsigned _revision;
|
unsigned _revision;
|
||||||
CPlusPlus::TokenCache _tokenCache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -736,8 +736,7 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
QString expr = plaintext->textCursor().selectedText();
|
QString expr = plaintext->textCursor().selectedText();
|
||||||
CppTools::CppModelManagerInterface *modelManager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
if (expr.isEmpty()) {
|
||||||
if (expr.isEmpty() && modelManager) {
|
|
||||||
QTextCursor tc(plaintext->document());
|
QTextCursor tc(plaintext->document());
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
|
|
||||||
@@ -746,7 +745,7 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|||||||
tc.movePosition(QTextCursor::EndOfWord);
|
tc.movePosition(QTextCursor::EndOfWord);
|
||||||
|
|
||||||
// Fetch the expression's code.
|
// Fetch the expression's code.
|
||||||
CPlusPlus::ExpressionUnderCursor expressionUnderCursor(modelManager->tokenCache(editor));
|
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
|
||||||
expr = expressionUnderCursor(tc);
|
expr = expressionUnderCursor(tc);
|
||||||
*column = tc.columnNumber();
|
*column = tc.columnNumber();
|
||||||
*line = tc.blockNumber();
|
*line = tc.blockNumber();
|
||||||
@@ -758,7 +757,7 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
|
|||||||
|
|
||||||
if (function && !expr.isEmpty())
|
if (function && !expr.isEmpty())
|
||||||
if (const Core::IFile *file = editor->file())
|
if (const Core::IFile *file = editor->file())
|
||||||
if (modelManager)
|
if (CppTools::CppModelManagerInterface *modelManager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>())
|
||||||
*function = CppTools::AbstractEditorSupport::functionAt(modelManager, file->fileName(), *line, *column);
|
*function = CppTools::AbstractEditorSupport::functionAt(modelManager, file->fileName(), *line, *column);
|
||||||
|
|
||||||
return expr;
|
return expr;
|
||||||
|
Reference in New Issue
Block a user