Clang: Fix slots and function pointers completion

Check completed functions for preceding & and
don't add parantheses in that case

Task-number: QTCREATORBUG-17578
Change-Id: I21b1e2c9ffb9d288f3267146e9afd575e6fef30b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2017-06-01 16:36:56 +02:00
parent f9f10a1e32
commit ae10749ffe

View File

@@ -111,43 +111,48 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
// in which case it would be annoying if we put the cursor after the already automatically // in which case it would be annoying if we put the cursor after the already automatically
// inserted closing parenthesis. // inserted closing parenthesis.
const bool skipClosingParenthesis = m_typedCharacter != QLatin1Char('('); const bool skipClosingParenthesis = m_typedCharacter != QLatin1Char('(');
QTextCursor cursor = manipulator.textCursorAt(basePosition);
cursor.movePosition(QTextCursor::PreviousWord);
while (manipulator.characterAt(cursor.position()) == ':')
cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 2);
if (manipulator.characterAt(cursor.position()) != '&') {
if (completionSettings.m_spaceAfterFunctionName)
extraCharacters += QLatin1Char(' ');
extraCharacters += QLatin1Char('(');
if (m_typedCharacter == QLatin1Char('('))
m_typedCharacter = QChar();
if (completionSettings.m_spaceAfterFunctionName) // If the function doesn't return anything, automatically place the semicolon,
extraCharacters += QLatin1Char(' '); // unless we're doing a scope completion (then it might be function definition).
extraCharacters += QLatin1Char('('); const QChar characterAtCursor = manipulator.characterAt(manipulator.currentPosition());
if (m_typedCharacter == QLatin1Char('(')) bool endWithSemicolon = m_typedCharacter == QLatin1Char(';')/*
m_typedCharacter = QChar(); || (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
const QChar semicolon = m_typedCharacter.isNull() ? QLatin1Char(';') : m_typedCharacter;
// If the function doesn't return anything, automatically place the semicolon, if (endWithSemicolon && characterAtCursor == semicolon) {
// unless we're doing a scope completion (then it might be function definition). endWithSemicolon = false;
const QChar characterAtCursor = manipulator.characterAt(manipulator.currentPosition());
bool endWithSemicolon = m_typedCharacter == QLatin1Char(';')/*
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
const QChar semicolon = m_typedCharacter.isNull() ? QLatin1Char(';') : m_typedCharacter;
if (endWithSemicolon && characterAtCursor == semicolon) {
endWithSemicolon = false;
m_typedCharacter = QChar();
}
// If the function takes no arguments, automatically place the closing parenthesis
if (!isOverloaded() && !ccr.hasParameters() && skipClosingParenthesis) {
extraCharacters += QLatin1Char(')');
if (endWithSemicolon) {
extraCharacters += semicolon;
m_typedCharacter = QChar(); m_typedCharacter = QChar();
} }
} else if (autoParenthesesEnabled) {
const QChar lookAhead = manipulator.characterAt(manipulator.currentPosition() + 1); // If the function takes no arguments, automatically place the closing parenthesis
if (MatchingText::shouldInsertMatchingText(lookAhead)) { if (!isOverloaded() && !ccr.hasParameters() && skipClosingParenthesis) {
extraCharacters += QLatin1Char(')'); extraCharacters += QLatin1Char(')');
--cursorOffset;
setAutoCompleteSkipPos = true;
if (endWithSemicolon) { if (endWithSemicolon) {
extraCharacters += semicolon; extraCharacters += semicolon;
--cursorOffset;
m_typedCharacter = QChar(); m_typedCharacter = QChar();
} }
} else if (autoParenthesesEnabled) {
const QChar lookAhead = manipulator.characterAt(manipulator.currentPosition() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraCharacters += QLatin1Char(')');
--cursorOffset;
setAutoCompleteSkipPos = true;
if (endWithSemicolon) {
extraCharacters += semicolon;
--cursorOffset;
m_typedCharacter = QChar();
}
}
} }
} }
} }