Commit 3be2c9df authored by hjk's avatar hjk

CppEditor: Simplify CppAutoCompleter header

Change-Id: Ie6c01ca4fb11b4b4c5e66618c9f8f0cb67e7845b
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 282864bd
...@@ -39,11 +39,50 @@ using namespace CppEditor; ...@@ -39,11 +39,50 @@ using namespace CppEditor;
using namespace Internal; using namespace Internal;
using namespace CPlusPlus; using namespace CPlusPlus;
CppAutoCompleter::CppAutoCompleter() static const Token tokenAtPosition(const QList<Token> &tokens, const unsigned pos)
{} {
for (int i = tokens.size() - 1; i >= 0; --i) {
const Token tk = tokens.at(i);
if (pos >= tk.utf16charsBegin() && pos < tk.utf16charsEnd())
return tk;
}
return Token();
}
static bool isInCommentHelper(const QTextCursor &cursor, Token *retToken = 0)
{
LanguageFeatures features;
features.qtEnabled = false;
features.qtKeywordsEnabled = false;
features.qtMocRunEnabled = false;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
CppAutoCompleter::~CppAutoCompleter() if (tokens.isEmpty() || pos < tokens.first().utf16charsBegin())
{} return prevState > 0;
if (pos >= tokens.last().utf16charsEnd()) {
const Token tk = tokens.last();
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return true;
return tk.isComment() && (cursor.block().userState() & 0xFF);
}
Token tk = tokenAtPosition(tokens, pos);
if (retToken)
*retToken = tk;
return tk.isComment();
}
bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const const QString &textToInsert) const
...@@ -99,47 +138,3 @@ QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) co ...@@ -99,47 +138,3 @@ QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) co
return m.insertParagraphSeparator(cursor); return m.insertParagraphSeparator(cursor);
} }
bool CppAutoCompleter::isInCommentHelper(const QTextCursor &cursor, Token *retToken) const
{
LanguageFeatures features;
features.qtEnabled = false;
features.qtKeywordsEnabled = false;
features.qtMocRunEnabled = false;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (tokens.isEmpty() || pos < tokens.first().utf16charsBegin())
return prevState > 0;
if (pos >= tokens.last().utf16charsEnd()) {
const Token tk = tokens.last();
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return true;
return tk.isComment() && (cursor.block().userState() & 0xFF);
}
Token tk = tokenAtPosition(tokens, pos);
if (retToken)
*retToken = tk;
return tk.isComment();
}
const Token CppAutoCompleter::tokenAtPosition(const QList<Token> &tokens, const unsigned pos) const
{
for (int i = tokens.size() - 1; i >= 0; --i) {
const Token tk = tokens.at(i);
if (pos >= tk.utf16charsBegin() && pos < tk.utf16charsEnd())
return tk;
}
return Token();
}
...@@ -32,16 +32,13 @@ ...@@ -32,16 +32,13 @@
#include <texteditor/autocompleter.h> #include <texteditor/autocompleter.h>
#include <cplusplus/Token.h>
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
class CppAutoCompleter : public TextEditor::AutoCompleter class CppAutoCompleter : public TextEditor::AutoCompleter
{ {
public: public:
CppAutoCompleter(); CppAutoCompleter() {}
virtual ~CppAutoCompleter();
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const; const QString &textToInsert = QString()) const;
...@@ -52,10 +49,6 @@ public: ...@@ -52,10 +49,6 @@ public:
QChar la, QChar la,
int *skippedChars) const; int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const; virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
private:
bool isInCommentHelper(const QTextCursor &cursor, CPlusPlus::Token *retToken = 0) const;
const CPlusPlus::Token tokenAtPosition(const QList<CPlusPlus::Token> &tokens, const unsigned pos) const;
}; };
} // Internal } // Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment