From ae10749ffe6f00af062aed543f8a6923879ea8af Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Thu, 1 Jun 2017 16:36:56 +0200 Subject: [PATCH] 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 --- .../clangassistproposalitem.cpp | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/plugins/clangcodemodel/clangassistproposalitem.cpp b/src/plugins/clangcodemodel/clangassistproposalitem.cpp index 67754a06c4b..012ac9af5e1 100644 --- a/src/plugins/clangcodemodel/clangassistproposalitem.cpp +++ b/src/plugins/clangcodemodel/clangassistproposalitem.cpp @@ -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 // inserted closing parenthesis. 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) - extraCharacters += QLatin1Char(' '); - extraCharacters += QLatin1Char('('); - if (m_typedCharacter == QLatin1Char('(')) - m_typedCharacter = QChar(); + // If the function doesn't return anything, automatically place the semicolon, + // unless we're doing a scope completion (then it might be function definition). + 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 the function doesn't return anything, automatically place the semicolon, - // unless we're doing a scope completion (then it might be function definition). - 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; + if (endWithSemicolon && characterAtCursor == semicolon) { + endWithSemicolon = false; m_typedCharacter = QChar(); } - } else if (autoParenthesesEnabled) { - const QChar lookAhead = manipulator.characterAt(manipulator.currentPosition() + 1); - if (MatchingText::shouldInsertMatchingText(lookAhead)) { + + // If the function takes no arguments, automatically place the closing parenthesis + if (!isOverloaded() && !ccr.hasParameters() && skipClosingParenthesis) { extraCharacters += QLatin1Char(')'); - --cursorOffset; - setAutoCompleteSkipPos = true; if (endWithSemicolon) { extraCharacters += semicolon; - --cursorOffset; 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(); + } + } } } }