forked from qt-creator/qt-creator
Codeformatter: Support indenting of type annotated function
Fixes: QTCREATORBUG-29046 Change-Id: Ie4a4d85b7aa00ddf4dd3ea4bade6ffa57af7b4e0 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
@@ -253,9 +253,16 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
||||
case function_arglist_closed:
|
||||
switch (kind) {
|
||||
case LeftBrace: turnInto(jsblock_open); break;
|
||||
case Colon: turnInto(function_type_annotated_return); break;
|
||||
default: leave(true); continue; // error recovery
|
||||
} break;
|
||||
|
||||
case function_type_annotated_return:
|
||||
switch (kind) {
|
||||
case LeftBrace: turnInto(jsblock_open); break;
|
||||
default: break;
|
||||
} break;
|
||||
|
||||
case expression_or_objectdefinition:
|
||||
switch (kind) {
|
||||
case Dot:
|
||||
|
@@ -99,6 +99,7 @@ public: // must be public to make Q_GADGET introspection work
|
||||
function_start, // after 'function'
|
||||
function_arglist_open, // after '(' starting function argument list
|
||||
function_arglist_closed, // after ')' in argument list, expecting '{'
|
||||
function_type_annotated_return, // after ':' expecting a type
|
||||
|
||||
binding_or_objectdefinition, // after an identifier
|
||||
|
||||
|
@@ -83,6 +83,7 @@ private Q_SLOTS:
|
||||
void bug1();
|
||||
void bug2();
|
||||
void bug3();
|
||||
void indentFunctionWithReturnTypeAnnotation();
|
||||
};
|
||||
|
||||
enum { DontCheck = -2, DontIndent = -1 };
|
||||
@@ -1564,6 +1565,18 @@ void tst_QMLCodeFormatter::bug3()
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
|
||||
void tst_QMLCodeFormatter::indentFunctionWithReturnTypeAnnotation()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("function test() : void {", 0)
|
||||
<< Line("", 4)
|
||||
<< Line(" }", 0)
|
||||
;
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_QMLCodeFormatter)
|
||||
#include "tst_qmlcodeformatter.moc"
|
||||
|
||||
|
Reference in New Issue
Block a user