Clang: Fix completion after '{'

Follow-up fix for 8d0391a4f9.

Do not complete after '{' coming not after an identifier.
Take constructor completions only for '{' and function
completions only for '('. Filter constructor completions by
class/struct type.

Task-number: QTCREATORBUG-21004
Change-Id: I7ae2d6bee23cf907648c42b93eb12742942833f6
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-08-28 12:17:33 +02:00
parent a6719ed0ff
commit 8b6a16c95b
4 changed files with 66 additions and 3 deletions

View File

@@ -68,6 +68,22 @@ static bool isDoxygenTagCompletionCharacter(const QChar &character)
|| character == QLatin1Char('@') ;
}
static bool twoIndentifiersBeforeLBrace(const Tokens &tokens, int tokenIdx)
{
const Token &previousToken = tokens.at(tokenIdx - 1);
if (previousToken.kind() != T_IDENTIFIER)
return false;
for (int index = tokenIdx - 2; index >= 0; index -= 2) {
const Token &token = tokens.at(index);
if (token.kind() == T_IDENTIFIER)
return true;
if (token.kind() != T_COLON_COLON)
return false;
}
return false;
}
void CppCompletionAssistProcessor::startOfOperator(QTextDocument *textDocument,
int positionInDocument,
unsigned *kind,
@@ -146,6 +162,11 @@ void CppCompletionAssistProcessor::startOfOperator(QTextDocument *textDocument,
start = positionInDocument;
}
}
} else if (*kind == T_LBRACE) {
if (tokenIdx > 0 && !twoIndentifiersBeforeLBrace(tokens, tokenIdx)) {
*kind = T_EOF_SYMBOL;
start = positionInDocument;
}
}
// Check for include preprocessor directive
else if (*kind == T_STRING_LITERAL || *kind == T_ANGLE_STRING_LITERAL || *kind == T_SLASH