forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/3.6'
Conflicts: qtcreator.pri qtcreator.qbs Change-Id: Ifbe181e86c161e082cc9a69a4bc7bd399f34ff47
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
void CompletionChunksToTextConverter::parseChunks(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
void CompletionChunksToTextConverter::parseChunks(
|
||||
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
{
|
||||
m_text.clear();
|
||||
m_placeholderPositions.clear();
|
||||
@@ -49,7 +50,7 @@ void CompletionChunksToTextConverter::parseChunks(const ClangBackEnd::CodeComple
|
||||
m_codeCompletionChunks.cend(),
|
||||
[this] (const ClangBackEnd::CodeCompletionChunk &chunk)
|
||||
{
|
||||
parse(chunk);
|
||||
parseDependendOnTheOptionalState(chunk);
|
||||
m_previousCodeCompletionChunk = chunk;
|
||||
});
|
||||
}
|
||||
@@ -74,14 +75,15 @@ void CompletionChunksToTextConverter::setAddSpaces(bool addSpaces)
|
||||
m_addSpaces = addSpaces;
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::setAddExtraVerticalSpaceBetweenBraces(bool addExtraVerticalSpaceBetweenBraces)
|
||||
void CompletionChunksToTextConverter::setAddExtraVerticalSpaceBetweenBraces(
|
||||
bool addExtraVerticalSpaceBetweenBraces)
|
||||
{
|
||||
m_addExtraVerticalSpaceBetweenBraces = addExtraVerticalSpaceBetweenBraces;
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::setAddHtmlTags(bool addHtmlTags)
|
||||
void CompletionChunksToTextConverter::setEmphasizeOptional(bool emphasizeOptional)
|
||||
{
|
||||
m_addHtmlTags = addHtmlTags;
|
||||
m_emphasizeOptional = emphasizeOptional;
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::setAddOptional(bool addOptional)
|
||||
@@ -89,6 +91,11 @@ void CompletionChunksToTextConverter::setAddOptional(bool addOptional)
|
||||
m_addOptional = addOptional;
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::setPlaceHolderToEmphasize(int placeHolderNumber)
|
||||
{
|
||||
m_placeHolderPositionToEmphasize = placeHolderNumber;
|
||||
}
|
||||
|
||||
const QString &CompletionChunksToTextConverter::text() const
|
||||
{
|
||||
return m_text;
|
||||
@@ -104,19 +111,27 @@ bool CompletionChunksToTextConverter::hasPlaceholderPositions() const
|
||||
return m_placeholderPositions.size() > 0;
|
||||
}
|
||||
|
||||
QString CompletionChunksToTextConverter::convertToFunctionSignature(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
QString CompletionChunksToTextConverter::convertToFunctionSignature(
|
||||
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
|
||||
int parameterToEmphasize)
|
||||
{
|
||||
CompletionChunksToTextConverter converter;
|
||||
converter.setAddPlaceHolderText(true);
|
||||
converter.setAddResultType(true);
|
||||
|
||||
converter.setAddOptional(true);
|
||||
converter.setEmphasizeOptional(true);
|
||||
|
||||
converter.setAddPlaceHolderPositions(true);
|
||||
converter.setPlaceHolderToEmphasize(parameterToEmphasize);
|
||||
|
||||
converter.parseChunks(codeCompletionChunks);
|
||||
|
||||
return converter.text();
|
||||
}
|
||||
|
||||
QString CompletionChunksToTextConverter::convertToName(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
QString CompletionChunksToTextConverter::convertToName(
|
||||
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
{
|
||||
CompletionChunksToTextConverter converter;
|
||||
|
||||
@@ -125,14 +140,15 @@ QString CompletionChunksToTextConverter::convertToName(const ClangBackEnd::CodeC
|
||||
return converter.text();
|
||||
}
|
||||
|
||||
QString CompletionChunksToTextConverter::convertToToolTip(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
QString CompletionChunksToTextConverter::convertToToolTip(
|
||||
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
|
||||
{
|
||||
CompletionChunksToTextConverter converter;
|
||||
converter.setAddPlaceHolderText(true);
|
||||
converter.setAddSpaces(true);
|
||||
converter.setAddExtraVerticalSpaceBetweenBraces(true);
|
||||
converter.setAddOptional(true);
|
||||
converter.setAddHtmlTags(true);
|
||||
converter.setEmphasizeOptional(true);
|
||||
converter.setAddResultType(true);
|
||||
|
||||
converter.parseChunks(codeCompletionChunks);
|
||||
@@ -140,13 +156,13 @@ QString CompletionChunksToTextConverter::convertToToolTip(const ClangBackEnd::Co
|
||||
return converter.text();
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parse(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
void CompletionChunksToTextConverter::parse(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
using ClangBackEnd::CodeCompletionChunk;
|
||||
|
||||
switch (codeCompletionChunk.kind()) {
|
||||
case CodeCompletionChunk::ResultType: parseResultType(codeCompletionChunk.text()); break;
|
||||
case CodeCompletionChunk::Optional: parseOptional(codeCompletionChunk); break;
|
||||
case CodeCompletionChunk::Placeholder: parsePlaceHolder(codeCompletionChunk); break;
|
||||
case CodeCompletionChunk::LeftParen: parseLeftParen(codeCompletionChunk); break;
|
||||
case CodeCompletionChunk::LeftBrace: parseLeftBrace(codeCompletionChunk); break;
|
||||
@@ -154,10 +170,19 @@ void CompletionChunksToTextConverter::parse(const ClangBackEnd::CodeCompletionCh
|
||||
}
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseDependendOnTheOptionalState(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
wrapInCursiveTagIfOptional(codeCompletionChunk);
|
||||
|
||||
if (isNotOptionalOrAddOptionals(codeCompletionChunk))
|
||||
parse(codeCompletionChunk);
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseResultType(const Utf8String &resultTypeText)
|
||||
{
|
||||
if (m_addResultType)
|
||||
m_text += resultTypeText.toString() + QChar(QChar::Space);
|
||||
m_text += resultTypeText.toString().toHtmlEscaped() + QChar(QChar::Space);
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseText(const Utf8String &text)
|
||||
@@ -167,32 +192,36 @@ void CompletionChunksToTextConverter::parseText(const Utf8String &text)
|
||||
m_text += QChar(QChar::Space);
|
||||
}
|
||||
|
||||
m_text += text.toString();
|
||||
m_text += text.toString().toHtmlEscaped();
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseOptional(const ClangBackEnd::CodeCompletionChunk &optionalCodeCompletionChunk)
|
||||
void CompletionChunksToTextConverter::wrapInCursiveTagIfOptional(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
if (m_addOptional) {
|
||||
if (m_addHtmlTags)
|
||||
m_text += QStringLiteral("<i>");
|
||||
|
||||
m_text += convertToFunctionSignature(optionalCodeCompletionChunk.optionalChunks());
|
||||
|
||||
if (m_addHtmlTags)
|
||||
m_text += QStringLiteral("</i>");
|
||||
if (m_emphasizeOptional) {
|
||||
if (!m_previousCodeCompletionChunk.isOptional() && codeCompletionChunk.isOptional())
|
||||
m_text += QStringLiteral("<i>");
|
||||
else if (m_previousCodeCompletionChunk.isOptional() && !codeCompletionChunk.isOptional())
|
||||
m_text += QStringLiteral("</i>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parsePlaceHolder(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
void CompletionChunksToTextConverter::parsePlaceHolder(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
if (m_addPlaceHolderText)
|
||||
m_text += codeCompletionChunk.text().toString();
|
||||
if (m_addPlaceHolderText) {
|
||||
appendText(codeCompletionChunk.text().toString().toHtmlEscaped(),
|
||||
emphasizeCurrentPlaceHolder());
|
||||
}
|
||||
|
||||
if (m_addPlaceHolderPositions)
|
||||
m_placeholderPositions.push_back(m_text.size());
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseLeftParen(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
void CompletionChunksToTextConverter::parseLeftParen(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
if (canAddSpace())
|
||||
m_text += QChar(QChar::Space);
|
||||
@@ -200,7 +229,8 @@ void CompletionChunksToTextConverter::parseLeftParen(const ClangBackEnd::CodeCom
|
||||
m_text += codeCompletionChunk.text().toString();
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::parseLeftBrace(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
void CompletionChunksToTextConverter::parseLeftBrace(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
|
||||
{
|
||||
if (canAddSpace())
|
||||
m_text += QChar(QChar::Space);
|
||||
@@ -214,7 +244,8 @@ void CompletionChunksToTextConverter::addExtraVerticalSpaceBetweenBraces()
|
||||
addExtraVerticalSpaceBetweenBraces(m_codeCompletionChunks.begin());
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::addExtraVerticalSpaceBetweenBraces(const ClangBackEnd::CodeCompletionChunks::iterator &begin)
|
||||
void CompletionChunksToTextConverter::addExtraVerticalSpaceBetweenBraces(
|
||||
const ClangBackEnd::CodeCompletionChunks::iterator &begin)
|
||||
{
|
||||
using ClangBackEnd::CodeCompletionChunk;
|
||||
|
||||
@@ -256,6 +287,24 @@ void CompletionChunksToTextConverter::addExtraVerticalSpaceBetweenBraces(const C
|
||||
}
|
||||
}
|
||||
|
||||
bool CompletionChunksToTextConverter::emphasizeCurrentPlaceHolder() const
|
||||
{
|
||||
if (m_addPlaceHolderPositions) {
|
||||
const uint currentPlaceHolderPosition = m_placeholderPositions.size() + 1;
|
||||
return uint(m_placeHolderPositionToEmphasize) == currentPlaceHolderPosition;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CompletionChunksToTextConverter::appendText(const QString &text, bool boldFormat)
|
||||
{
|
||||
if (boldFormat)
|
||||
m_text += QStringLiteral("<b>") + text + QStringLiteral("</b>");
|
||||
else
|
||||
m_text += text;
|
||||
}
|
||||
|
||||
bool CompletionChunksToTextConverter::canAddSpace() const
|
||||
{
|
||||
return m_addSpaces
|
||||
@@ -263,6 +312,12 @@ bool CompletionChunksToTextConverter::canAddSpace() const
|
||||
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::RightAngle;
|
||||
}
|
||||
|
||||
bool CompletionChunksToTextConverter::isNotOptionalOrAddOptionals(
|
||||
const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk) const
|
||||
{
|
||||
return !codeCompletionChunk.isOptional() || m_addOptional;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
|
||||
@@ -52,40 +52,48 @@ public:
|
||||
void setAddResultType(bool addResultType);
|
||||
void setAddSpaces(bool addSpaces);
|
||||
void setAddExtraVerticalSpaceBetweenBraces(bool addExtraVerticalSpaceBetweenBraces);
|
||||
void setAddHtmlTags(bool addHtmlTags);
|
||||
void setEmphasizeOptional(bool emphasizeOptional);
|
||||
void setAddOptional(bool addOptional);
|
||||
void setPlaceHolderToEmphasize(int placeHolderNumber);
|
||||
|
||||
const QString &text() const;
|
||||
const std::vector<int> &placeholderPositions() const;
|
||||
bool hasPlaceholderPositions() const;
|
||||
|
||||
static QString convertToFunctionSignature(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
|
||||
static QString convertToFunctionSignature(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
|
||||
int parameterToEmphasize = -1);
|
||||
static QString convertToName(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
|
||||
static QString convertToToolTip(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
|
||||
private:
|
||||
void parse(const ClangBackEnd::CodeCompletionChunk & codeCompletionChunk);
|
||||
void parse(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void parseDependendOnTheOptionalState(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void parseResultType(const Utf8String &text);
|
||||
void parseText(const Utf8String &text);
|
||||
void parseOptional(const ClangBackEnd::CodeCompletionChunk &optionalCodeCompletionChunk);
|
||||
void wrapInCursiveTagIfOptional(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void parsePlaceHolder(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void parseLeftParen(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void parseLeftBrace(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk);
|
||||
void addExtraVerticalSpaceBetweenBraces();
|
||||
void addExtraVerticalSpaceBetweenBraces(const ClangBackEnd::CodeCompletionChunks::iterator &);
|
||||
|
||||
void appendText(const QString &text, bool boldFormat = false);
|
||||
bool canAddSpace() const;
|
||||
bool isNotOptionalOrAddOptionals(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk) const;
|
||||
|
||||
bool emphasizeCurrentPlaceHolder() const;
|
||||
|
||||
private:
|
||||
std::vector<int> m_placeholderPositions;
|
||||
ClangBackEnd::CodeCompletionChunks m_codeCompletionChunks;
|
||||
ClangBackEnd::CodeCompletionChunk m_previousCodeCompletionChunk;
|
||||
QString m_text;
|
||||
int m_placeHolderPositionToEmphasize = -1;
|
||||
bool m_addPlaceHolderText = false;
|
||||
bool m_addPlaceHolderPositions = false;
|
||||
bool m_addResultType = false;
|
||||
bool m_addSpaces = false;
|
||||
bool m_addExtraVerticalSpaceBetweenBraces = false;
|
||||
bool m_addHtmlTags = false;
|
||||
bool m_emphasizeOptional = false;
|
||||
bool m_addOptional = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ using namespace CPlusPlus;
|
||||
|
||||
ClangFunctionHintModel::ClangFunctionHintModel(const ClangBackEnd::CodeCompletions &functionSymbols)
|
||||
: m_functionSymbols(functionSymbols)
|
||||
, m_currentArg(-1)
|
||||
, m_currentArgument(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,52 +56,61 @@ int ClangFunctionHintModel::size() const
|
||||
|
||||
QString ClangFunctionHintModel::text(int index) const
|
||||
{
|
||||
#if 0
|
||||
// TODO: add the boldening to the result
|
||||
Overview overview;
|
||||
overview.setShowReturnTypes(true);
|
||||
overview.setShowArgumentNames(true);
|
||||
overview.setMarkedArgument(m_currentArg + 1);
|
||||
Function *f = m_functionSymbols.at(index);
|
||||
const ClangBackEnd::CodeCompletionChunks chunks = m_functionSymbols.at(index).chunks();
|
||||
const QString signatureWithEmphasizedCurrentParameter
|
||||
= CompletionChunksToTextConverter::convertToFunctionSignature(chunks, m_currentArgument + 1);
|
||||
|
||||
const QString prettyMethod = overview(f->type(), f->name());
|
||||
const int begin = overview.markedArgumentBegin();
|
||||
const int end = overview.markedArgumentEnd();
|
||||
|
||||
QString hintText;
|
||||
hintText += prettyMethod.left(begin).toHtmlEscaped());
|
||||
hintText += "<b>";
|
||||
hintText += prettyMethod.mid(begin, end - begin).toHtmlEscaped());
|
||||
hintText += "</b>";
|
||||
hintText += prettyMethod.mid(end).toHtmlEscaped());
|
||||
return hintText;
|
||||
#endif
|
||||
return CompletionChunksToTextConverter::convertToFunctionSignature(m_functionSymbols.at(index).chunks());
|
||||
return signatureWithEmphasizedCurrentParameter;
|
||||
}
|
||||
|
||||
int ClangFunctionHintModel::activeArgument(const QString &prefix) const
|
||||
{
|
||||
int argnr = 0;
|
||||
int parcount = 0;
|
||||
int activeArgumentNumber = 0;
|
||||
|
||||
int unbalancedParens = 0; // expressions
|
||||
int unbalancedBraces = 0; // initializer lists
|
||||
int unbalancedBrackets = 0; // lambda-capture
|
||||
int unbalancedLessGreater = 0; // template arguments
|
||||
|
||||
SimpleLexer tokenize;
|
||||
Tokens tokens = tokenize(prefix);
|
||||
for (int i = 0; i < tokens.count(); ++i) {
|
||||
const Token &tk = tokens.at(i);
|
||||
if (tk.is(T_LPAREN))
|
||||
++parcount;
|
||||
else if (tk.is(T_RPAREN))
|
||||
--parcount;
|
||||
else if (! parcount && tk.is(T_COMMA))
|
||||
++argnr;
|
||||
const Tokens tokens = tokenize(prefix);
|
||||
for (const Token &token : tokens) {
|
||||
if (token.is(T_LPAREN)) {
|
||||
++unbalancedParens;
|
||||
} else if (token.is(T_RPAREN)) {
|
||||
--unbalancedParens;
|
||||
} else if (token.is(T_LBRACE)) {
|
||||
++unbalancedBraces;
|
||||
} else if (token.is(T_RBRACE)) {
|
||||
--unbalancedBraces;
|
||||
} else if (token.is(T_LBRACKET)) {
|
||||
++unbalancedBrackets;
|
||||
} else if (token.is(T_RBRACKET)) {
|
||||
--unbalancedBrackets;
|
||||
} else if (token.is(T_LESS)) {
|
||||
++unbalancedLessGreater;
|
||||
} else if (token.is(T_GREATER)) {
|
||||
--unbalancedLessGreater;
|
||||
} else if (!unbalancedParens
|
||||
&& !unbalancedBraces
|
||||
&& !unbalancedBrackets
|
||||
&& !unbalancedLessGreater
|
||||
&& token.is(T_COMMA)) {
|
||||
++activeArgumentNumber;
|
||||
}
|
||||
}
|
||||
|
||||
if (parcount < 0)
|
||||
if (unbalancedParens < 0
|
||||
|| unbalancedBraces < 0
|
||||
|| unbalancedBrackets < 0
|
||||
|| unbalancedLessGreater < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (argnr != m_currentArg)
|
||||
m_currentArg = argnr;
|
||||
if (activeArgumentNumber != m_currentArgument)
|
||||
m_currentArgument = activeArgumentNumber;
|
||||
|
||||
return argnr;
|
||||
return activeArgumentNumber;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
ClangBackEnd::CodeCompletions m_functionSymbols;
|
||||
mutable int m_currentArg;
|
||||
mutable int m_currentArgument;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -914,11 +914,11 @@ void ClangCodeCompletionTest::testCompleteFunctions()
|
||||
|
||||
QVERIFY(hasItem(t.proposal, "void f()"));
|
||||
QVERIFY(hasItem(t.proposal, "void f(int a)"));
|
||||
QVERIFY(hasItem(t.proposal, "void f(const QString &s)"));
|
||||
QVERIFY(hasItem(t.proposal, "void f(char c, int optional)")); // TODO: No default argument?
|
||||
QVERIFY(hasItem(t.proposal, "void f(char c, int optional1, int optional2)")); // TODO: No default argument?
|
||||
QVERIFY(hasItem(t.proposal, "void f(const TType<QString> *t)"));
|
||||
QVERIFY(hasItem(t.proposal, "TType<QString> f(bool)"));
|
||||
QVERIFY(hasItem(t.proposal, "void f(const QString &s)"));
|
||||
QVERIFY(hasItem(t.proposal, "void f(char c<i>, int optional</i>)")); // TODO: No default argument?
|
||||
QVERIFY(hasItem(t.proposal, "void f(char c<i>, int optional1, int optional2</i>)")); // TODO: No default argument?
|
||||
QVERIFY(hasItem(t.proposal, "void f(const TType<QString> *t)"));
|
||||
QVERIFY(hasItem(t.proposal, "TType<QString> f(bool)"));
|
||||
}
|
||||
|
||||
void ClangCodeCompletionTest::testCompleteConstructorAndFallbackToGlobalCompletion()
|
||||
|
||||
Reference in New Issue
Block a user