Commit fbd549f2 authored by Marco Bubke's avatar Marco Bubke
Browse files

Clang: Prevent double spaces for clang snippets



Change-Id: I62f9b9c217570dd6dafc45719e898cc2ac4d2937
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent f9899c2d
......@@ -136,9 +136,10 @@ void CompletionChunksToTextConverter::parseResultType(const Utf8String &resultTy
void CompletionChunksToTextConverter::parseText(const Utf8String &text)
{
if (m_addSpaces
&& m_previousCodeCompletionChunk.kind() == ClangBackEnd::CodeCompletionChunk::RightBrace)
if (canAddSpace()
&& m_previousCodeCompletionChunk.kind() == ClangBackEnd::CodeCompletionChunk::RightBrace) {
m_text += QChar(QChar::Space);
}
m_text += text.toString();
}
......@@ -163,7 +164,7 @@ void CompletionChunksToTextConverter::parsePlaceHolder(const ClangBackEnd::CodeC
void CompletionChunksToTextConverter::parseLeftParen(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
{
if (m_addSpaces && m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::RightAngle)
if (canAddSpace())
m_text += QChar(QChar::Space);
m_text += codeCompletionChunk.text().toString();
......@@ -171,7 +172,7 @@ void CompletionChunksToTextConverter::parseLeftParen(const ClangBackEnd::CodeCom
void CompletionChunksToTextConverter::parseLeftBrace(const ClangBackEnd::CodeCompletionChunk &codeCompletionChunk)
{
if (m_addSpaces)
if (canAddSpace())
m_text += QChar(QChar::Space);
m_text += codeCompletionChunk.text().toString();
......@@ -225,6 +226,13 @@ void CompletionChunksToTextConverter::addExtraVerticalSpaceBetweenBraces(const Q
}
}
bool CompletionChunksToTextConverter::canAddSpace() const
{
return m_addSpaces
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::HorizontalSpace
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::RightAngle;
}
} // namespace Internal
} // namespace ClangCodeModel
......@@ -71,6 +71,8 @@ private:
void addExtraVerticalSpaceBetweenBraces();
void addExtraVerticalSpaceBetweenBraces(const QVector<ClangBackEnd::CodeCompletionChunk>::iterator &);
bool canAddSpace() const;
private:
std::vector<int> m_placeholderPositions;
QVector<ClangBackEnd::CodeCompletionChunk> m_codeCompletionChunks;
......
......@@ -76,6 +76,9 @@ protected:
CodeCompletionChunk constCastName{CodeCompletionChunk::TypedText, Utf8StringLiteral("const_cast")};
CodeCompletionChunk leftAngle{CodeCompletionChunk::LeftAngle, Utf8StringLiteral("<")};
CodeCompletionChunk rightAngle{CodeCompletionChunk::RightAngle, Utf8StringLiteral(">")};
CodeCompletionChunk elseName{CodeCompletionChunk::TypedText, Utf8StringLiteral("else")};
CodeCompletionChunk ifName{CodeCompletionChunk::TypedText, Utf8StringLiteral("if")};
CodeCompletionChunk horizontalSpace{CodeCompletionChunk::HorizontalSpace, Utf8StringLiteral(" ")};
CodeCompletionChunk optional{CodeCompletionChunk::Optional, Utf8String(), {comma, functionArgumentY, comma, functionArgumentZ}};
};
......@@ -201,7 +204,6 @@ TEST_F(CompletionChunksToTextConverter, const_cast)
converter.parseChunks(completionChunks);
ASSERT_THAT(converter.text(), QStringLiteral("const_cast<>()"));
}
TEST_F(CompletionChunksToTextConverter, Throw)
......@@ -213,6 +215,25 @@ TEST_F(CompletionChunksToTextConverter, Throw)
ASSERT_THAT(completionName, QStringLiteral("throw"));
}
TEST_F(CompletionChunksToTextConverter, ElseIf)
{
QVector<CodeCompletionChunk> completionChunks({elseName,
horizontalSpace,
ifName,
horizontalSpace,
leftBrace,
verticalSpace,
statements,
verticalSpace,
rightBrace});
setupConverterForKeywords();
converter.parseChunks(completionChunks);
ASSERT_THAT(converter.text(), QStringLiteral("else if {\n\n}"));
}
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