summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-10-20 20:09:00 +0200
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2009-10-20 20:09:00 +0200
commitc9f9310bb19c024140d842059d9c831caa430257 (patch)
treeebcc3a6e0f56a6b7a412b8939a547a5f45324146 /src/plugins/cpptools/cppcodecompletion.cpp
parent202fef42ca2104a7113958c0cbfbdf1cce2024f8 (diff)
parentb8daa7d5a76ace846ada49dd900cf6b3112a477b (diff)
downloadqt-creator-c9f9310bb19c024140d842059d9c831caa430257.tar.gz
Merge remote branch 'origin/1.3'
Conflicts: src/plugins/cpptools/cppcodecompletion.cpp src/plugins/debugger/gdb/remotegdbadapter.cpp
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp87
1 files changed, 50 insertions, 37 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index ec58883712..edaafcc890 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -565,63 +565,63 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
const QChar ch3 = pos > 1 ? editor->characterAt(pos - 3) : QChar();
int start = pos;
- int k = T_EOF_SYMBOL;
+ int completionKind = T_EOF_SYMBOL;
switch (ch.toLatin1()) {
case '.':
if (ch2 != QLatin1Char('.')) {
- k = T_DOT;
+ completionKind = T_DOT;
--start;
}
break;
case ',':
- k = T_COMMA;
+ completionKind = T_COMMA;
--start;
break;
case '(':
if (wantFunctionCall) {
- k = T_LPAREN;
+ completionKind = T_LPAREN;
--start;
}
break;
case ':':
if (ch3 != QLatin1Char(':') && ch2 == QLatin1Char(':')) {
- k = T_COLON_COLON;
+ completionKind = T_COLON_COLON;
start -= 2;
}
break;
case '>':
if (ch2 == QLatin1Char('-')) {
- k = T_ARROW;
+ completionKind = T_ARROW;
start -= 2;
}
break;
case '*':
if (ch2 == QLatin1Char('.')) {
- k = T_DOT_STAR;
+ completionKind = T_DOT_STAR;
start -= 2;
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>')) {
- k = T_ARROW_STAR;
+ completionKind = T_ARROW_STAR;
start -= 3;
}
break;
case '\\':
case '@':
if (ch2.isNull() || ch2.isSpace()) {
- k = T_DOXY_COMMENT;
+ completionKind = T_DOXY_COMMENT;
--start;
}
break;
case '<':
- k = T_ANGLE_STRING_LITERAL;
+ completionKind = T_ANGLE_STRING_LITERAL;
--start;
break;
case '"':
- k = T_STRING_LITERAL;
+ completionKind = T_STRING_LITERAL;
--start;
break;
case '/':
- k = T_SLASH;
+ completionKind = T_SLASH;
--start;
break;
}
@@ -634,20 +634,20 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
tc.setPosition(pos);
// Include completion: make sure the quote character is the first one on the line
- if (k == T_STRING_LITERAL) {
+ if (completionKind == T_STRING_LITERAL) {
QTextCursor s = tc;
s.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
QString sel = s.selectedText();
if (sel.indexOf(QLatin1Char('"')) < sel.length() - 1) {
- k = T_EOF_SYMBOL;
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
}
- if (k == T_COMMA) {
+ if (completionKind == T_COMMA) {
ExpressionUnderCursor expressionUnderCursor;
if (expressionUnderCursor.startOfFunctionCall(tc) == -1) {
- k = T_EOF_SYMBOL;
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
}
@@ -655,24 +655,24 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
static CPlusPlus::TokenUnderCursor tokenUnderCursor;
const SimpleToken tk = tokenUnderCursor(tc);
- if (k == T_DOXY_COMMENT && tk.isNot(T_DOXY_COMMENT)) {
- k = T_EOF_SYMBOL;
+ if (completionKind == T_DOXY_COMMENT && !(tk.is(T_DOXY_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))) {
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
// Don't complete in comments or strings, but still check for include completion
- else if (tk.is(T_COMMENT) || (tk.isLiteral() &&
- (k != T_STRING_LITERAL
- && k != T_ANGLE_STRING_LITERAL
- && k != T_SLASH))) {
- k = T_EOF_SYMBOL;
+ else if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT) ||
+ (tk.isLiteral() && (completionKind != T_STRING_LITERAL
+ && completionKind != T_ANGLE_STRING_LITERAL
+ && completionKind != T_SLASH))) {
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
// Include completion: can be triggered by slash, but only in a string
- else if (k == T_SLASH && (tk.isNot(T_STRING_LITERAL) && tk.isNot(T_ANGLE_STRING_LITERAL))) {
- k = T_EOF_SYMBOL;
+ else if (completionKind == T_SLASH && (tk.isNot(T_STRING_LITERAL) && tk.isNot(T_ANGLE_STRING_LITERAL))) {
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
- else if (k == T_LPAREN) {
+ else if (completionKind == T_LPAREN) {
const QList<SimpleToken> &tokens = tokenUnderCursor.tokens();
int i = 0;
for (; i < tokens.size(); ++i) {
@@ -688,12 +688,12 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
}
if (i == tokens.size()) {
- k = T_EOF_SYMBOL;
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
}
// Check for include preprocessor directive
- else if (k == T_STRING_LITERAL || k == T_ANGLE_STRING_LITERAL || k == T_SLASH) {
+ else if (completionKind == T_STRING_LITERAL || completionKind == T_ANGLE_STRING_LITERAL || completionKind == T_SLASH) {
bool include = false;
const QList<SimpleToken> &tokens = tokenUnderCursor.tokens();
if (tokens.size() >= 3) {
@@ -709,13 +709,13 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
}
if (!include) {
- k = T_EOF_SYMBOL;
+ completionKind = T_EOF_SYMBOL;
start = pos;
}
}
if (kind)
- *kind = k;
+ *kind = completionKind;
return start;
}
@@ -1022,8 +1022,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
// find a scope that encloses the current location, starting from the lastVisibileSymbol
// and moving outwards
- Scope *sc = context.symbol()->scope();
- while (sc->enclosingScope()) {
+ Scope *sc = 0;
+ if (context.symbol())
+ sc = context.symbol()->scope();
+ else if (context.thisDocument())
+ sc = context.thisDocument()->globalSymbols();
+
+ while (sc && sc->enclosingScope()) {
unsigned startLine, startColumn;
context.thisDocument()->translationUnit()->getPosition(sc->owner()->startOffset(), &startLine, &startColumn);
unsigned endLine, endColumn;
@@ -1037,7 +1042,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
sc = sc->enclosingScope();
}
- if (sc->isClassScope() || sc->isNamespaceScope())
+ if (sc && (sc->isClassScope() || sc->isNamespaceScope()))
{
// It may still be a function call. If the whole line parses as a function
// declaration, we should be certain that it isn't.
@@ -1066,10 +1071,18 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
Overview overview;
overview.setShowArgumentNames(true);
- TextEditor::CompletionItem item(this);
- item.text = overview(f->type());
- item.text = item.text.mid(1, item.text.size()-2);
- m_completions.append(item);
+ // get rid of parentheses and cv-qualifiers
+ QString completion = overview(f->type());
+ if (f->isVolatile() || f->isConst())
+ completion = completion.mid(1, completion.lastIndexOf(')') - 1);
+ else
+ completion = completion.mid(1, completion.size() - 2);
+
+ if (completion.size()) {
+ TextEditor::CompletionItem item(this);
+ item.text = completion;
+ m_completions.append(item);
+ }
}
return true;
}