Commit 8c3c882a authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Fix parsing of enable_if_t



Task-number: QTCREATORBUG-11864
Change-Id: Ifd0d3482bc4f4373394734d4b173304db32a6a2d
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 66ba8fe6
......@@ -79,6 +79,16 @@ void CompletionChunksToTextConverter::setAddExtraVerticalSpaceBetweenBraces(bool
m_addExtraVerticalSpaceBetweenBraces = addExtraVerticalSpaceBetweenBraces;
}
void CompletionChunksToTextConverter::setAddHtmlTags(bool addHtmlTags)
{
m_addHtmlTags = addHtmlTags;
}
void CompletionChunksToTextConverter::setAddOptional(bool addOptional)
{
m_addOptional = addOptional;
}
const QString &CompletionChunksToTextConverter::text() const
{
return m_text;
......@@ -99,6 +109,7 @@ QString CompletionChunksToTextConverter::convertToFunctionSignature(const ClangB
CompletionChunksToTextConverter converter;
converter.setAddPlaceHolderText(true);
converter.setAddResultType(true);
converter.setAddOptional(true);
converter.parseChunks(codeCompletionChunks);
......@@ -120,6 +131,9 @@ QString CompletionChunksToTextConverter::convertToToolTip(const ClangBackEnd::Co
converter.setAddPlaceHolderText(true);
converter.setAddSpaces(true);
converter.setAddExtraVerticalSpaceBetweenBraces(true);
converter.setAddOptional(true);
converter.setAddHtmlTags(true);
converter.setAddResultType(true);
converter.parseChunks(codeCompletionChunks);
......@@ -158,11 +172,15 @@ void CompletionChunksToTextConverter::parseText(const Utf8String &text)
void CompletionChunksToTextConverter::parseOptional(const ClangBackEnd::CodeCompletionChunk &optionalCodeCompletionChunk)
{
m_text += QStringLiteral("<i>");
if (m_addOptional) {
if (m_addHtmlTags)
m_text += QStringLiteral("<i>");
m_text += convertToFunctionSignature(optionalCodeCompletionChunk.optionalChunks());
m_text += convertToFunctionSignature(optionalCodeCompletionChunk.optionalChunks());
m_text += QStringLiteral("</i>");
if (m_addHtmlTags)
m_text += QStringLiteral("</i>");
}
}
void CompletionChunksToTextConverter::parsePlaceHolder(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
......
......@@ -52,6 +52,8 @@ public:
void setAddResultType(bool addResultType);
void setAddSpaces(bool addSpaces);
void setAddExtraVerticalSpaceBetweenBraces(bool addExtraVerticalSpaceBetweenBraces);
void setAddHtmlTags(bool addHtmlTags);
void setAddOptional(bool addOptional);
const QString &text() const;
const std::vector<int> &placeholderPositions() const;
......@@ -83,6 +85,8 @@ private:
bool m_addResultType = false;
bool m_addSpaces = false;
bool m_addExtraVerticalSpaceBetweenBraces = false;
bool m_addHtmlTags = false;
bool m_addOptional = false;
};
} // namespace Internal
......
......@@ -868,8 +868,8 @@ 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<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(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)"));
}
......
......@@ -81,6 +81,9 @@ protected:
CodeCompletionChunk ifName{CodeCompletionChunk::TypedText, Utf8StringLiteral("if")};
CodeCompletionChunk horizontalSpace{CodeCompletionChunk::HorizontalSpace, Utf8StringLiteral(" ")};
CodeCompletionChunk optional{CodeCompletionChunk::Optional, Utf8String(), {comma, functionArgumentY, comma, functionArgumentZ}};
CodeCompletionChunk enableIfT{CodeCompletionChunk::TypedText, Utf8StringLiteral("enable_if_t")};
CodeCompletionChunk enableIfTCondition{CodeCompletionChunk::Placeholder, Utf8StringLiteral("_Cond")};
CodeCompletionChunk enableIfTType{CodeCompletionChunk::Placeholder, Utf8StringLiteral("_Tp")};
};
TEST_F(CompletionChunksToTextConverter, ParseIsClearingText)
......@@ -117,12 +120,9 @@ TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithParameters)
TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithOptionalParameter)
{
CodeCompletionChunks completionChunks({integerResultType, functionName, leftParen, functionArgumentX, optional,rightParen});
converter.setAddResultType(true);
converter.setAddPlaceHolderText(true);
converter.parseChunks(completionChunks);
ASSERT_THAT(converter.text(), QStringLiteral("int Function(char x<i>, int y, int z</i>)"));
ASSERT_THAT(Converter::convertToToolTip(completionChunks),
QStringLiteral("int Function (char x<i>, int y, int z</i>)"));
}
TEST_F(CompletionChunksToTextConverter, ConvertVariable)
......@@ -227,7 +227,6 @@ TEST_F(CompletionChunksToTextConverter, ElseIf)
statements,
verticalSpace,
rightBrace});
setupConverterForKeywords();
converter.parseChunks(completionChunks);
......@@ -235,6 +234,20 @@ TEST_F(CompletionChunksToTextConverter, ElseIf)
ASSERT_THAT(converter.text(), QStringLiteral("else if {\n\n}"));
}
TEST_F(CompletionChunksToTextConverter, EnableIfT)
{
CodeCompletionChunks completionChunks({enableIfT,
leftAngle,
enableIfTCondition,
CodeCompletionChunk(CodeCompletionChunk::Optional, Utf8String(), {comma, enableIfTType}),
rightAngle});
setupConverterForKeywords();
converter.parseChunks(completionChunks);
ASSERT_THAT(converter.text(), QStringLiteral("enable_if_t<>"));
}
void CompletionChunksToTextConverter::setupConverterForKeywords()
{
converter.setAddPlaceHolderPositions(true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment