forked from qt-creator/qt-creator
109 lines
2.9 KiB
C++
109 lines
2.9 KiB
C++
|
|
#include "cppcompletionassistprovider.h"
|
||
|
|
|
||
|
|
#include <cppeditor/cppeditorconstants.h>
|
||
|
|
|
||
|
|
#include <Token.h>
|
||
|
|
|
||
|
|
using namespace CPlusPlus;
|
||
|
|
using namespace CppTools;
|
||
|
|
|
||
|
|
// ---------------------------
|
||
|
|
// CppCompletionAssistProvider
|
||
|
|
// ---------------------------
|
||
|
|
bool CppCompletionAssistProvider::supportsEditor(const Core::Id &editorId) const
|
||
|
|
{
|
||
|
|
return editorId == Core::Id(CppEditor::Constants::CPPEDITOR_ID);
|
||
|
|
}
|
||
|
|
|
||
|
|
int CppCompletionAssistProvider::activationCharSequenceLength() const
|
||
|
|
{
|
||
|
|
return 3;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool CppCompletionAssistProvider::isActivationCharSequence(const QString &sequence) const
|
||
|
|
{
|
||
|
|
const QChar &ch = sequence.at(2);
|
||
|
|
const QChar &ch2 = sequence.at(1);
|
||
|
|
const QChar &ch3 = sequence.at(0);
|
||
|
|
if (activationSequenceChar(ch, ch2, ch3, 0, true) != 0)
|
||
|
|
return true;
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
int CppCompletionAssistProvider::activationSequenceChar(const QChar &ch,
|
||
|
|
const QChar &ch2,
|
||
|
|
const QChar &ch3,
|
||
|
|
unsigned *kind,
|
||
|
|
bool wantFunctionCall)
|
||
|
|
{
|
||
|
|
int referencePosition = 0;
|
||
|
|
int completionKind = T_EOF_SYMBOL;
|
||
|
|
switch (ch.toLatin1()) {
|
||
|
|
case '.':
|
||
|
|
if (ch2 != QLatin1Char('.')) {
|
||
|
|
completionKind = T_DOT;
|
||
|
|
referencePosition = 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ',':
|
||
|
|
completionKind = T_COMMA;
|
||
|
|
referencePosition = 1;
|
||
|
|
break;
|
||
|
|
case '(':
|
||
|
|
if (wantFunctionCall) {
|
||
|
|
completionKind = T_LPAREN;
|
||
|
|
referencePosition = 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ':':
|
||
|
|
if (ch3 != QLatin1Char(':') && ch2 == QLatin1Char(':')) {
|
||
|
|
completionKind = T_COLON_COLON;
|
||
|
|
referencePosition = 2;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case '>':
|
||
|
|
if (ch2 == QLatin1Char('-')) {
|
||
|
|
completionKind = T_ARROW;
|
||
|
|
referencePosition = 2;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case '*':
|
||
|
|
if (ch2 == QLatin1Char('.')) {
|
||
|
|
completionKind = T_DOT_STAR;
|
||
|
|
referencePosition = 2;
|
||
|
|
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>')) {
|
||
|
|
completionKind = T_ARROW_STAR;
|
||
|
|
referencePosition = 3;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case '\\':
|
||
|
|
case '@':
|
||
|
|
if (ch2.isNull() || ch2.isSpace()) {
|
||
|
|
completionKind = T_DOXY_COMMENT;
|
||
|
|
referencePosition = 1;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case '<':
|
||
|
|
completionKind = T_ANGLE_STRING_LITERAL;
|
||
|
|
referencePosition = 1;
|
||
|
|
break;
|
||
|
|
case '"':
|
||
|
|
completionKind = T_STRING_LITERAL;
|
||
|
|
referencePosition = 1;
|
||
|
|
break;
|
||
|
|
case '/':
|
||
|
|
completionKind = T_SLASH;
|
||
|
|
referencePosition = 1;
|
||
|
|
break;
|
||
|
|
case '#':
|
||
|
|
completionKind = T_POUND;
|
||
|
|
referencePosition = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (kind)
|
||
|
|
*kind = completionKind;
|
||
|
|
|
||
|
|
return referencePosition;
|
||
|
|
}
|