Commit 33a2288c authored by Ivan Donchevskii's avatar Ivan Donchevskii

Clang: Fix extra space before left paren

Do not add space before left paren in function
because it must not be there

Task-number: QTCREATORBUG-14878
Change-Id: I0fd0e650aeeee59af7bbc157c2fae652109763bc
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent ca72c294
......@@ -279,7 +279,8 @@ QIcon ClangAssistProposalItem::icon() const
QString ClangAssistProposalItem::detail() const
{
QString detail = CompletionChunksToTextConverter::convertToToolTipWithHtml(m_codeCompletion.chunks());
QString detail = CompletionChunksToTextConverter::convertToToolTipWithHtml(
m_codeCompletion.chunks(), m_codeCompletion.completionKind());
if (!m_codeCompletion.briefComment().isEmpty())
detail += QStringLiteral("\n\n") + m_codeCompletion.briefComment().toString();
......
......@@ -91,6 +91,11 @@ void CompletionChunksToTextConverter::setPlaceHolderToEmphasize(int placeHolderN
m_placeHolderPositionToEmphasize = placeHolderNumber;
}
void CompletionChunksToTextConverter::setCompletionKind(const ClangBackEnd::CodeCompletion::Kind kind)
{
m_codeCompletionKind = kind;
}
void CompletionChunksToTextConverter::setupForKeywords()
{
setAddPlaceHolderPositions(true);
......@@ -115,6 +120,7 @@ bool CompletionChunksToTextConverter::hasPlaceholderPositions() const
QString CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
ClangBackEnd::CodeCompletion::Kind codeCompletionKind,
int parameterToEmphasize)
{
CompletionChunksToTextConverter converter;
......@@ -127,6 +133,7 @@ QString CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(
converter.setAddPlaceHolderPositions(true);
converter.setPlaceHolderToEmphasize(parameterToEmphasize);
converter.setCompletionKind(codeCompletionKind);
converter.parseChunks(codeCompletionChunks);
......@@ -144,7 +151,8 @@ QString CompletionChunksToTextConverter::convertToName(
}
QString CompletionChunksToTextConverter::convertToToolTipWithHtml(
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks)
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
ClangBackEnd::CodeCompletion::Kind codeCompletionKind)
{
CompletionChunksToTextConverter converter;
converter.setAddPlaceHolderText(true);
......@@ -154,6 +162,7 @@ QString CompletionChunksToTextConverter::convertToToolTipWithHtml(
converter.setTextFormat(TextFormat::Html);
converter.setEmphasizeOptional(true);
converter.setAddResultType(true);
converter.setCompletionKind(codeCompletionKind);
converter.parseChunks(codeCompletionChunks);
......@@ -233,7 +242,6 @@ void CompletionChunksToTextConverter::parseLeftParen(
{
if (canAddSpace())
m_text += QChar(QChar::Space);
m_text += codeCompletionChunk.text().toString();
}
......@@ -330,7 +338,8 @@ bool CompletionChunksToTextConverter::canAddSpace() const
{
return m_addSpaces
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::HorizontalSpace
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::RightAngle;
&& m_previousCodeCompletionChunk.kind() != ClangBackEnd::CodeCompletionChunk::RightAngle
&& m_codeCompletionKind != ClangBackEnd::CodeCompletion::FunctionCompletionKind;
}
bool CompletionChunksToTextConverter::isNotOptionalOrAddOptionals(
......
......@@ -25,7 +25,7 @@
#pragma once
#include <clangbackendipc/codecompletionchunk.h>
#include <clangbackendipc/codecompletion.h>
#include <sqlite/utf8string.h>
......@@ -54,6 +54,7 @@ public:
void setEmphasizeOptional(bool emphasizeOptional); // Only for Html format
void setAddOptional(bool addOptional);
void setPlaceHolderToEmphasize(int placeHolderNumber);
void setCompletionKind(const ClangBackEnd::CodeCompletion::Kind kind);
void setupForKeywords();
......@@ -63,9 +64,12 @@ public:
static QString convertToName(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
static QString convertToKeywords(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
static QString convertToToolTipWithHtml(const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks);
static QString convertToToolTipWithHtml(
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
ClangBackEnd::CodeCompletion::Kind codeCompletionKind);
static QString convertToFunctionSignatureWithHtml(
const ClangBackEnd::CodeCompletionChunks &codeCompletionChunks,
ClangBackEnd::CodeCompletion::Kind codeCompletionKind,
int parameterToEmphasize = -1);
private:
......@@ -94,6 +98,7 @@ private:
QString m_text;
int m_placeHolderPositionToEmphasize = -1;
TextFormat m_textFormat = TextFormat::Plain;
ClangBackEnd::CodeCompletion::Kind m_codeCompletionKind = ClangBackEnd::CodeCompletion::Other;
bool m_addPlaceHolderText = false;
bool m_addPlaceHolderPositions = false;
bool m_addResultType = false;
......
......@@ -53,8 +53,10 @@ QString ClangFunctionHintModel::text(int index) const
{
const ClangBackEnd::CodeCompletionChunks chunks = m_functionSymbols.at(index).chunks();
const QString signatureWithEmphasizedCurrentParameter
= CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(chunks,
m_currentArgument + 1);
= CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(
chunks,
m_functionSymbols.at(index).completionKind(),
m_currentArgument + 1);
return signatureWithEmphasizedCurrentParameter;
}
......
......@@ -123,7 +123,9 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithOneArgumen
functionArgumentXAsCurrentParameter,
rightParen});
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(completionChunks),
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind),
QStringLiteral("int Function(char x)"));
}
......@@ -135,7 +137,10 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithOneParamet
functionArgumentXAsCurrentParameter,
rightParen});
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(completionChunks, 1),
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind,
1),
QStringLiteral("int Function(<b>char x</b>)"));
}
......@@ -149,7 +154,10 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithTwoParamet
functionArgumentYAsCurrentParamter,
rightParen});
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(completionChunks, 2),
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind,
2),
QStringLiteral("int Function(char x, <b>int y</b>)"));
}
......@@ -163,7 +171,10 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithTwoParamet
optionalFunctionArgumentYAsCurrentParameter,
rightParen});
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(completionChunks, 2),
ASSERT_THAT(converter.convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind,
2),
QStringLiteral("int Function(char x<i>, <b>int y</b></i>)"));
}
......@@ -177,7 +188,9 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithTemplateRe
using ClangCodeModel::Internal::CompletionChunksToTextConverter;
ASSERT_THAT(CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(completionChunks),
ASSERT_THAT(CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind),
QStringLiteral("Foo&lt;int&gt; Function(char x)"));
}
......@@ -191,7 +204,9 @@ TEST_F(CompletionChunksToTextConverter, ConvertToFunctionSignatureWithTemplateAr
using ClangCodeModel::Internal::CompletionChunksToTextConverter;
ASSERT_THAT(CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(completionChunks),
ASSERT_THAT(CompletionChunksToTextConverter::convertToFunctionSignatureWithHtml(
completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind),
QStringLiteral("int Function(const Foo&lt;int&gt; &amp;foo)"));
}
......@@ -207,8 +222,9 @@ TEST_F(CompletionChunksToTextConverter, ConvertFunctionWithOptionalParameter)
optionalFunctionArgumentZ,
rightParen});
ASSERT_THAT(Converter::convertToToolTipWithHtml(completionChunks),
QStringLiteral("int Function (char x<i>, int y, int z</i>)"));
ASSERT_THAT(Converter::convertToToolTipWithHtml(completionChunks,
ClangBackEnd::CodeCompletion::FunctionCompletionKind),
QStringLiteral("int Function(char x<i>, int y, int z</i>)"));
}
TEST_F(CompletionChunksToTextConverter, ConvertVariable)
......
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