diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-07-05 11:03:52 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-07-05 11:06:15 +0200 |
commit | 3a88dc624f8b25ec1edb32c13029459ddadfc09f (patch) | |
tree | c3a97376f85e2ab5f97859b741a3c1ded0076da3 /src/plugins/cpptools/cppcodecompletion.cpp | |
parent | c5bc38df6d86e16a5da87e2a23fcbd016a4fa6cb (diff) | |
download | qt-creator-3a88dc624f8b25ec1edb32c13029459ddadfc09f.tar.gz |
Fixed function-like code completion.
This was a regression introduced in 8e4fb678fd68cbb01d5548ba07dfcb2927868df4
triggersCompletion should return `true' when the token at the left of the T_LPAREN
is an identifier, a SIGNAL, a SLOT or T_GREATER (for template functions).
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index ab45c47369..03e6a9f28d 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -556,8 +556,8 @@ static int startOfOperator(TextEditor::ITextEditable *editor, tokenize.setQtMocRunEnabled(true); tokenize.setSkipComments(false); const QList<Token> &tokens = tokenize(tc.block().text()); - const int tokenIdx = SimpleLexer::tokenAt(tokens, tc.positionInBlock()); - const Token &tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx); + const int tokenIdx = SimpleLexer::tokenAt(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor + const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx); if (completionKind == T_DOXY_COMMENT && !(tk.is(T_DOXY_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))) { completionKind = T_EOF_SYMBOL; @@ -577,23 +577,21 @@ static int startOfOperator(TextEditor::ITextEditable *editor, start = pos; } else if (completionKind == T_LPAREN) { - int i = 0; - for (; i < tokens.size(); ++i) { - const Token &token = tokens.at(i); - if (token.begin() == tk.begin()) { - if (i == 0) // no token on the left, but might be on a previous line - break; - const Token &previousToken = tokens.at(i - 1); - if (previousToken.is(T_IDENTIFIER) || previousToken.is(T_GREATER) - || previousToken.is(T_SIGNAL) || previousToken.is(T_SLOT)) - break; + if (tokenIdx > 0) { + const Token &previousToken = tokens.at(tokenIdx - 1); // look at the token at the left of T_LPAREN + switch (previousToken.kind()) { + case T_IDENTIFIER: + case T_GREATER: + case T_SIGNAL: + case T_SLOT: + break; // good + + default: + // that's a bad token :) + completionKind = T_EOF_SYMBOL; + start = pos; } } - - if (i == tokens.size()) { - completionKind = T_EOF_SYMBOL; - start = pos; - } } // Check for include preprocessor directive else if (completionKind == T_STRING_LITERAL || completionKind == T_ANGLE_STRING_LITERAL || completionKind == T_SLASH) { |