Clang: Fix cursor position after completion of overloads

struct Foo {
    void begin();
    void begin() const;
};

void c(Foo &foo)
{
    foo.beg // complete to foo.begin()| instead of foo.begin(|)
}

Task-number: QTCREATORBUG-17443
Change-Id: I60ca16bbfeeb75c5c37a0d5bc6f46e9e9913b86e
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Nikolai Kosjar
2017-08-11 12:29:30 +02:00
parent e5631e2ebe
commit 415d3c4784
3 changed files with 16 additions and 14 deletions

View File

@@ -154,7 +154,7 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
}
// If the function takes no arguments, automatically place the closing parenthesis
if (!isOverloaded() && !ccr.hasParameters() && skipClosingParenthesis) {
if (!hasOverloadsWithParameters() && !ccr.hasParameters() && skipClosingParenthesis) {
extraCharacters += QLatin1Char(')');
if (endWithSemicolon) {
extraCharacters += semicolon;
@@ -333,21 +333,21 @@ quint64 ClangAssistProposalItem::hash() const
return 0;
}
bool ClangAssistProposalItem::hasOverloadsWithParameters() const
{
return m_hasOverloadsWithParameters;
}
void ClangAssistProposalItem::setHasOverloadsWithParameters(bool hasOverloadsWithParameters)
{
m_hasOverloadsWithParameters = hasOverloadsWithParameters;
}
void ClangAssistProposalItem::keepCompletionOperator(unsigned compOp)
{
m_completionOperator = compOp;
}
bool ClangAssistProposalItem::isOverloaded() const
{
return !m_overloads.isEmpty();
}
void ClangAssistProposalItem::addOverload(const CodeCompletion &ccr)
{
m_overloads.append(ccr);
}
void ClangAssistProposalItem::setCodeCompletion(const CodeCompletion &codeCompletion)
{
m_codeCompletion = codeCompletion;

View File

@@ -53,8 +53,8 @@ public:
void keepCompletionOperator(unsigned compOp);
bool isOverloaded() const;
void addOverload(const ClangBackEnd::CodeCompletion &ccr);
bool hasOverloadsWithParameters() const;
void setHasOverloadsWithParameters(bool hasOverloadsWithParameters);
void setCodeCompletion(const ClangBackEnd::CodeCompletion &codeCompletion);
const ClangBackEnd::CodeCompletion &codeCompletion() const;
@@ -62,6 +62,7 @@ public:
private:
ClangBackEnd::CodeCompletion m_codeCompletion;
QList<ClangBackEnd::CodeCompletion> m_overloads;
bool m_hasOverloadsWithParameters = false;
QString m_text;
unsigned m_completionOperator;
mutable QChar m_typedCharacter;

View File

@@ -89,7 +89,8 @@ QList<AssistProposalItemInterface *> toAssistProposalItems(const CodeCompletions
ClangAssistProposalItem *item = items.value(name, 0);
if (item) {
item->addOverload(codeCompletion);
if (codeCompletion.hasParameters())
item->setHasOverloadsWithParameters(true);
} else {
item = new ClangAssistProposalItem;
items.insert(name, item);