From 323ba720db49d76e135f509a0782ff7486a5b52e Mon Sep 17 00:00:00 2001 From: Artem Sokolovskii Date: Mon, 16 May 2022 13:57:20 +0200 Subject: [PATCH] ClangFormat: Remove format while typing feature Change-Id: I6737c429694218d39fc06c9ef3ce502228e26a2a Reviewed-by: Reviewed-by: Christian Kandeler --- src/plugins/clangformat/clangformatbaseindenter.cpp | 12 ------------ src/plugins/clangformat/tests/clangformat-test.cpp | 12 ++++++------ src/plugins/clangformat/tests/clangformat-test.h | 4 ++-- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/plugins/clangformat/clangformatbaseindenter.cpp b/src/plugins/clangformat/clangformatbaseindenter.cpp index b9ee78b50ef..900d910dc39 100644 --- a/src/plugins/clangformat/clangformatbaseindenter.cpp +++ b/src/plugins/clangformat/clangformatbaseindenter.cpp @@ -594,18 +594,6 @@ Utils::Text::Replacements ClangFormatBaseIndenter::indentsFor(QTextBlock startBl const QByteArray buffer = m_doc->toPlainText().toUtf8(); ReplacementsToKeep replacementsToKeep = ReplacementsToKeep::OnlyIndent; - if (formatCodeInsteadOfIndent() - && (cursorPositionInEditor == -1 || cursorPositionInEditor >= startBlockPosition) - && (typedChar == ';' || typedChar == '}')) { - // Format before current position only in case the cursor is inside the indented block. - // So if cursor position is less then the block position then the current line is before - // the indented block - don't trigger extra formatting in this case. - // cursorPositionInEditor == -1 means the condition matches automatically. - - // Format only before complete statement not to break code. - replacementsToKeep = ReplacementsToKeep::IndentAndBefore; - } - return replacements(buffer, startBlock, endBlock, diff --git a/src/plugins/clangformat/tests/clangformat-test.cpp b/src/plugins/clangformat/tests/clangformat-test.cpp index 174a3d11705..af066963c79 100644 --- a/src/plugins/clangformat/tests/clangformat-test.cpp +++ b/src/plugins/clangformat/tests/clangformat-test.cpp @@ -471,7 +471,7 @@ void ClangFormatTest::testIndentAfterFunctionBodyAndNotFormatBefore() void ClangFormatTest::testReformatToEmptyFunction() { insertLines({"int foo(int a, int b, int c, int d)", "{", " ", "}"}); - m_extendedIndenter->indentBlock(m_doc->findBlockByNumber(3), '}', TextEditor::TabSettings()); + m_extendedIndenter->format({{1, 4}}); QCOMPARE(documentLines(), (std::vector{"int foo(int a, int b, int c, int d) {}"})); } @@ -483,10 +483,10 @@ void ClangFormatTest::testReformatToNonEmptyFunction() QCOMPARE(documentLines(), (std::vector{"int foo(int a, int b) {", " ", "}"})); } -void ClangFormatTest::testIndentClosingScopeAndFormatBeforeIt() +void ClangFormatTest::testFormatClosingScope() { insertLines({"if(a && b", " &&c && d", " ) {", "", "}"}); - m_extendedIndenter->indentBlock(m_doc->findBlockByNumber(4), '}', TextEditor::TabSettings()); + m_extendedIndenter->format({{1, 5}}); QCOMPARE(documentLines(), (std::vector{"if (a && b && c && d) {", "}"})); } @@ -504,17 +504,17 @@ void ClangFormatTest::testOnlyIndentIncompleteStatementOnElectricalCharacter() QCOMPARE(documentLines(), (std::vector{"{bar();", " foo()", "}"})); } -void ClangFormatTest::testIndentAndFormatCompleteStatementOnSemicolon() +void ClangFormatTest::testFormatCompleteStatementOnSemicolon() { insertLines({"{bar();", "foo();", "}"}); - m_extendedIndenter->indentBlock(m_doc->findBlockByNumber(1), ';', TextEditor::TabSettings(), 14); + m_extendedIndenter->format({{1, 3}}); QCOMPARE(documentLines(), (std::vector{"{", " bar();", " foo();", "}"})); } void ClangFormatTest::testIndentAndFormatCompleteStatementOnClosingScope() { insertLines({"{bar();", "foo();", "}"}); - m_extendedIndenter->indentBlock(m_doc->findBlockByNumber(1), '}', TextEditor::TabSettings(), 16); + m_extendedIndenter->format({{1, 3}}); QCOMPARE(documentLines(), (std::vector{"{", " bar();", " foo();", "}"})); } diff --git a/src/plugins/clangformat/tests/clangformat-test.h b/src/plugins/clangformat/tests/clangformat-test.h index 094657d1b01..ed7c3b16a1f 100644 --- a/src/plugins/clangformat/tests/clangformat-test.h +++ b/src/plugins/clangformat/tests/clangformat-test.h @@ -90,10 +90,10 @@ private slots: void testIndentAfterFunctionBodyAndNotFormatBefore(); void testReformatToEmptyFunction(); void testReformatToNonEmptyFunction(); - void testIndentClosingScopeAndFormatBeforeIt(); + void testFormatClosingScope(); void testDoNotFormatAfterTheFirstColon(); void testOnlyIndentIncompleteStatementOnElectricalCharacter(); - void testIndentAndFormatCompleteStatementOnSemicolon(); + void testFormatCompleteStatementOnSemicolon(); void testIndentAndFormatCompleteStatementOnClosingScope(); void testOnlyIndentClosingParenthesis(); void testEquallyIndentInsideParenthesis();