aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangformat
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2022-10-24 16:39:20 +0200
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2022-10-26 07:21:07 +0000
commitafed126ba1bb32d43c0a26d6ed58dcca87f6522a (patch)
tree9cfcaf826e2ec8711c5cb3473dc616bea123e102 /src/plugins/clangformat
parent02024303b10a370d7329b52d48c294aac300795c (diff)
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>
Diffstat (limited to 'src/plugins/clangformat')
-rw-r--r--src/plugins/clangformat/clangformatbaseindenter.cpp4
-rw-r--r--src/plugins/clangformat/tests/clangformat-test.cpp20
-rw-r--r--src/plugins/clangformat/tests/clangformat-test.h1
3 files changed, 23 insertions, 2 deletions
diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp
index cda7b54d5e..7c83c8e43b 100644
--- a/src/plugins/clangformat/clangformatbaseindenter.cpp
+++ b/src/plugins/clangformat/clangformatbaseindenter.cpp
@@ -250,7 +250,7 @@ QByteArray dummyTextForContext(CharacterContext context, bool closingBraceBlock)
case CharacterContext::IfOrElseWithoutScope:
return ";";
case CharacterContext::NewStatementOrContinuation:
- return "/**/";
+ return "/*//*/";
case CharacterContext::Unknown:
default:
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.
- if (dummyText == "/**/" || dummyText.isEmpty()) {
+ if (dummyText == "/*//*/" || dummyText.isEmpty()) {
if (block.previous().isValid()) {
const int prevEndOffset = Utils::Text::utf8NthLineOffset(block.document(), buffer,
block.blockNumber()) + block.previous().text().length();
diff --git a/src/plugins/clangformat/tests/clangformat-test.cpp b/src/plugins/clangformat/tests/clangformat-test.cpp
index 74107a40e7..161c20406c 100644
--- a/src/plugins/clangformat/tests/clangformat-test.cpp
+++ b/src/plugins/clangformat/tests/clangformat-test.cpp
@@ -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
diff --git a/src/plugins/clangformat/tests/clangformat-test.h b/src/plugins/clangformat/tests/clangformat-test.h
index 0cb909c034..a9c146ef8a 100644
--- a/src/plugins/clangformat/tests/clangformat-test.h
+++ b/src/plugins/clangformat/tests/clangformat-test.h
@@ -90,6 +90,7 @@ private slots:
void testClassIndentStructure();
void testIndentInitializeVector();
void testIndentFunctionArgumentOnNewLine();
+ void testIndentCommentOnNewLine();
private:
void insertLines(const std::vector<QString> &lines);