Format generic function references and constructor tear-offs. (#1047)
* Format generic function references and constructor tear-offs.
Fix #1028.
* Bump the minor version.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1baf14..a037247 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 2.1.0-dev
+
+* Support generic function references and constructor tear-offs (#1028).
+
# 2.0.3
* Fix hang when reading from stdin (https://github.com/dart-lang/sdk/issues/46600).
diff --git a/lib/src/dart_formatter.dart b/lib/src/dart_formatter.dart
index 7f437a9..2510ace 100644
--- a/lib/src/dart_formatter.dart
+++ b/lib/src/dart_formatter.dart
@@ -89,6 +89,7 @@
var featureSet = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version(2, 13, 0),
flags: [
+ 'constructor-tearoffs',
'generic-metadata',
'nonfunction-type-aliases',
'triple-shift'
diff --git a/lib/src/source_visitor.dart b/lib/src/source_visitor.dart
index d08f18f..4a53ae6 100644
--- a/lib/src/source_visitor.dart
+++ b/lib/src/source_visitor.dart
@@ -1806,6 +1806,12 @@
}
@override
+ void visitFunctionReference(FunctionReference node) {
+ visit(node.function);
+ visit(node.typeArguments);
+ }
+
+ @override
void visitFunctionTypeAlias(FunctionTypeAlias node) {
visitMetadata(node.metadata);
diff --git a/pubspec.yaml b/pubspec.yaml
index ab6ef20..c796bc2 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: dart_style
# Note: See tool/grind.dart for how to bump the version.
-version: 2.0.3
+version: 2.1.0-dev
description: >-
Opinionated, automatic Dart source code formatter.
Provides an API and a CLI tool.
diff --git a/test/splitting/mixed.stmt b/test/splitting/mixed.stmt
index 7d8dfff..f14c4ef 100644
--- a/test/splitting/mixed.stmt
+++ b/test/splitting/mixed.stmt
@@ -222,4 +222,12 @@
<<<
var longVariableName =
identifierSoLongItWraps
- is SomeClassName;
\ No newline at end of file
+ is SomeClassName;
+>>> generic function reference nested inside expression
+veryLongFunction(argument, ConstructorTearOff<First, Second, Third, Fourth>, argument);
+<<<
+veryLongFunction(
+ argument,
+ ConstructorTearOff<First, Second,
+ Third, Fourth>,
+ argument);
\ No newline at end of file
diff --git a/test/splitting/type_arguments.stmt b/test/splitting/type_arguments.stmt
index 9675153..77a2eb3 100644
--- a/test/splitting/type_arguments.stmt
+++ b/test/splitting/type_arguments.stmt
@@ -94,4 +94,43 @@
fifth,
sixth,
seventh,
- eighth);
\ No newline at end of file
+ eighth);
+>>> generic instantiation all fit on one line
+Foo<A,B,C,D>;
+<<<
+Foo<A, B, C, D>;
+>>> generic instantiation split between args
+LongClassName<First, Second, Third, Fourth>;
+<<<
+LongClassName<First, Second, Third,
+ Fourth>;
+>>> generic instantiation split before first if needed
+LongClassName<FirstTypeArgumentIsTooLong, Second>;
+<<<
+LongClassName<
+ FirstTypeArgumentIsTooLong, Second>;
+>>> generic instantiation split in middle if fit in two lines
+LongClassName<First, Second, Third, Fourth, Fifth, Sixth, Seventh>;
+<<<
+LongClassName<First, Second, Third,
+ Fourth, Fifth, Sixth, Seventh>;
+>>> generic instantiation split one per line if they don't fit in two lines
+LongClassName<First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>;
+<<<
+LongClassName<
+ First,
+ Second,
+ Third,
+ Fourth,
+ Fifth,
+ Sixth,
+ Seventh,
+ Eighth>;
+>>> generic instantiation indent nested type arguments
+LongClassName<First, Inner<Second, Third, Fourth, Fifth, Sixth, Seventh>, Eighth>;
+<<<
+LongClassName<
+ First,
+ Inner<Second, Third, Fourth, Fifth,
+ Sixth, Seventh>,
+ Eighth>;
\ No newline at end of file
diff --git a/test/whitespace/expressions.stmt b/test/whitespace/expressions.stmt
index 1a138dc..23502ab 100644
--- a/test/whitespace/expressions.stmt
+++ b/test/whitespace/expressions.stmt
@@ -170,4 +170,20 @@
>>> generic function expression
var generic = < T,S >(){};
<<<
-var generic = <T, S>() {};
\ No newline at end of file
+var generic = <T, S>() {};
+>>> generic method instantiation
+void main() => id < int > ;
+<<<
+void main() => id<int>;
+>>> generic method instantiation
+void main() => id < int , String , bool > ;
+<<<
+void main() => id<int, String, bool>;
+>>> generic constructor tear-off
+var x = Class < int >;
+<<<
+var x = Class<int>;
+>>> generic name constructor tear-off
+var x = Class < int > . named;
+<<<
+var x = Class<int>.named;
\ No newline at end of file