forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.4'
Conflicts: src/tools/clangbackend/ipcsource/clangiasyncjob.cpp src/tools/clangbackend/ipcsource/clangjobrequest.cpp src/tools/clangbackend/ipcsource/clangjobrequest.h Change-Id: Ib8602530663813ade418f995dfd2a736908cfe75
This commit is contained in:
@@ -32,10 +32,10 @@
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
#include <texteditor/completionsettings.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace ClangBackEnd;
|
||||
|
||||
@@ -66,6 +66,14 @@ bool ClangAssistProposalItem::implicitlyApplies() const
|
||||
return true;
|
||||
}
|
||||
|
||||
static void moveToPrevChar(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
QTextCursor &cursor)
|
||||
{
|
||||
cursor.movePosition(QTextCursor::PreviousCharacter);
|
||||
while (manipulator.characterAt(cursor.position()).isSpace())
|
||||
cursor.movePosition(QTextCursor::PreviousCharacter);
|
||||
}
|
||||
|
||||
void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||
int basePosition) const
|
||||
{
|
||||
@@ -78,12 +86,11 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
bool setAutoCompleteSkipPos = false;
|
||||
int currentPosition = manipulator.currentPosition();
|
||||
|
||||
bool autoParenthesesEnabled = true;
|
||||
if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
||||
extraCharacters += QLatin1Char(')');
|
||||
if (m_typedCharacter == QLatin1Char('(')) // Eat the opening parenthesis
|
||||
m_typedCharacter = QChar();
|
||||
} else if (ccr.completionKind() == CodeCompletion::KeywordCompletionKind) {
|
||||
} else if (ccr.completionKind() == CodeCompletion::KeywordCompletionKind) {
|
||||
CompletionChunksToTextConverter converter;
|
||||
converter.setupForKeywords();
|
||||
|
||||
@@ -116,7 +123,17 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
cursor.movePosition(QTextCursor::PreviousWord);
|
||||
while (manipulator.characterAt(cursor.position()) == ':')
|
||||
cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 2);
|
||||
if (manipulator.characterAt(cursor.position()) != '&') {
|
||||
|
||||
// Move to the last character in the previous word
|
||||
cursor.movePosition(QTextCursor::NextWord);
|
||||
moveToPrevChar(manipulator, cursor);
|
||||
bool abandonParen = false;
|
||||
if (manipulator.characterAt(cursor.position()) == '&') {
|
||||
moveToPrevChar(manipulator, cursor);
|
||||
const QChar prevChar = manipulator.characterAt(cursor.position());
|
||||
abandonParen = QString("(;,{}").contains(prevChar);
|
||||
}
|
||||
if (!abandonParen) {
|
||||
if (completionSettings.m_spaceAfterFunctionName)
|
||||
extraCharacters += QLatin1Char(' ');
|
||||
extraCharacters += QLatin1Char('(');
|
||||
@@ -136,13 +153,13 @@ 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;
|
||||
m_typedCharacter = QChar();
|
||||
}
|
||||
} else if (autoParenthesesEnabled) {
|
||||
} else {
|
||||
const QChar lookAhead = manipulator.characterAt(manipulator.currentPosition() + 1);
|
||||
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
|
||||
extraCharacters += QLatin1Char(')');
|
||||
@@ -157,19 +174,6 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (autoInsertBrackets && data().canConvert<CompleteFunctionDeclaration>()) {
|
||||
if (m_typedChar == QLatin1Char('('))
|
||||
m_typedChar = QChar();
|
||||
|
||||
// everything from the closing parenthesis on are extra chars, to
|
||||
// make sure an auto-inserted ")" gets replaced by ") const" if necessary
|
||||
int closingParen = toInsert.lastIndexOf(QLatin1Char(')'));
|
||||
extraChars = toInsert.mid(closingParen);
|
||||
toInsert.truncate(closingParen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Append an unhandled typed character, adjusting cursor offset when it had been adjusted before
|
||||
@@ -315,21 +319,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;
|
||||
@@ -342,4 +346,3 @@ const ClangBackEnd::CodeCompletion &ClangAssistProposalItem::codeCompletion() co
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -799,7 +799,7 @@ void ClangCodeCompletionTest::testCompleteGlobals()
|
||||
ProjectLessCompletionTest t("globalCompletion.cpp");
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "globalVariable", "int globalVariable"));
|
||||
QVERIFY(hasItem(t.proposal, "globalFunction", "void globalFunction ()"));
|
||||
QVERIFY(hasItem(t.proposal, "globalFunction", "void globalFunction()"));
|
||||
QVERIFY(hasItem(t.proposal, "GlobalClass", "GlobalClass"));
|
||||
QVERIFY(hasItem(t.proposal, "class", "class")); // Keyword
|
||||
QVERIFY(hasSnippet(t.proposal, "class")); // Snippet
|
||||
|
||||
Reference in New Issue
Block a user