ClangFormat: Fix wrong comment indentation

Fixes: QTCREATORBUG-25539
Change-Id: Ifecc4bc2c0984319d858720d5bcd1788a9008e90
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Artem Sokolovskii
2022-10-24 16:39:20 +02:00
parent 02024303b1
commit afed126ba1
3 changed files with 23 additions and 2 deletions

View File

@@ -250,7 +250,7 @@ QByteArray dummyTextForContext(CharacterContext context, bool closingBraceBlock)
case CharacterContext::IfOrElseWithoutScope: case CharacterContext::IfOrElseWithoutScope:
return ";"; return ";";
case CharacterContext::NewStatementOrContinuation: case CharacterContext::NewStatementOrContinuation:
return "/**/"; return "/*//*/";
case CharacterContext::Unknown: case CharacterContext::Unknown:
default: default:
QTC_ASSERT(false, return "";); QTC_ASSERT(false, return "";);
@@ -302,7 +302,7 @@ int forceIndentWithExtraText(QByteArray &buffer,
} }
// A comment at the end of the line appears to prevent clang-format from removing line breaks. // A comment at the end of the line appears to prevent clang-format from removing line breaks.
if (dummyText == "/**/" || dummyText.isEmpty()) { if (dummyText == "/*//*/" || dummyText.isEmpty()) {
if (block.previous().isValid()) { if (block.previous().isValid()) {
const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer, const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer,
block.blockNumber()) + block.previous().text().length(); block.blockNumber()) + block.previous().text().length();

View File

@@ -704,4 +704,24 @@ void ClangFormatTest::testIndentFunctionArgumentOnNewLine()
})); }));
} }
void ClangFormatTest::testIndentCommentOnNewLine()
{
insertLines(
{"/*!",
" \\qmlproperty double Type::property",
" ",
" \\brief The property of Type.",
"*/"
});
m_indenter->indent(*m_cursor, QChar::Null, TextEditor::TabSettings());
QCOMPARE(documentLines(),
(std::vector<QString>{
"/*!",
" \\qmlproperty double Type::property",
" ",
" \\brief The property of Type.",
"*/"
}));
}
} // namespace ClangFormat::Internal } // namespace ClangFormat::Internal

View File

@@ -90,6 +90,7 @@ private slots:
void testClassIndentStructure(); void testClassIndentStructure();
void testIndentInitializeVector(); void testIndentInitializeVector();
void testIndentFunctionArgumentOnNewLine(); void testIndentFunctionArgumentOnNewLine();
void testIndentCommentOnNewLine();
private: private:
void insertLines(const std::vector<QString> &lines); void insertLines(const std::vector<QString> &lines);