File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -1291,6 +1291,7 @@ extension Formatter {
1291
1291
/// - `some ...`
1292
1292
/// - `borrowing ...`
1293
1293
/// - `consuming ...`
1294
+ /// - `(type).(type)`
1294
1295
func parseType( at startOfTypeIndex: Int ) -> ( name: String , range: ClosedRange < Int > ) ? {
1295
1296
guard let baseType = parseNonOptionalType ( at: startOfTypeIndex) else { return nil }
1296
1297
@@ -1302,6 +1303,16 @@ extension Formatter {
1302
1303
return ( name: tokens [ typeRange] . string, range: typeRange)
1303
1304
}
1304
1305
1306
+ // Any type can be followed by a `.` which can then continue the type
1307
+ if let nextTokenIndex = index ( of: . nonSpaceOrCommentOrLinebreak, after: baseType. range. upperBound) ,
1308
+ tokens [ nextTokenIndex] == . operator( " . " , . infix) ,
1309
+ let followingToken = index ( of: . nonSpaceOrCommentOrLinebreak, after: nextTokenIndex) ,
1310
+ let followingType = parseType ( at: followingToken)
1311
+ {
1312
+ let typeRange = startOfTypeIndex ... followingType. range. upperBound
1313
+ return ( name: tokens [ typeRange] . string, range: typeRange)
1314
+ }
1315
+
1305
1316
return baseType
1306
1317
}
1307
1318
Original file line number Diff line number Diff line change @@ -1746,6 +1746,27 @@ class ParsingHelpersTests: XCTestCase {
1746
1746
XCTAssertEqual ( formatter. parseType ( at: 5 ) ? . name, " any Foo " )
1747
1747
}
1748
1748
1749
+ func testParseCompoundType( ) {
1750
+ let formatter = Formatter ( tokenize ( """
1751
+ let foo: Foo.Bar.Baaz
1752
+ """ ) )
1753
+ XCTAssertEqual ( formatter. parseType ( at: 5 ) ? . name, " Foo.Bar.Baaz " )
1754
+ }
1755
+
1756
+ func testParseCompoundGenericType( ) {
1757
+ let formatter = Formatter ( tokenize ( """
1758
+ let foo: Foo<Bar>.Bar.Baaz<Quux.V2>
1759
+ """ ) )
1760
+ XCTAssertEqual ( formatter. parseType ( at: 5 ) ? . name, " Foo<Bar>.Bar.Baaz<Quux.V2> " )
1761
+ }
1762
+
1763
+ func testParseExistentialTypeWithSubtype( ) {
1764
+ let formatter = Formatter ( tokenize ( """
1765
+ let foo: (any Foo).Bar.Baaz
1766
+ """ ) )
1767
+ XCTAssertEqual ( formatter. parseType ( at: 5 ) ? . name, " (any Foo).Bar.Baaz " )
1768
+ }
1769
+
1749
1770
func testParseOpaqueReturnType( ) {
1750
1771
let formatter = Formatter ( tokenize ( """
1751
1772
var body: some View { EmptyView() }
Original file line number Diff line number Diff line change @@ -4843,6 +4843,20 @@ class WrappingTests: RulesTests {
4843
4843
testFormatting ( for: input, rule: FormatRules . wrapAttributes, options: options)
4844
4844
}
4845
4845
4846
+ func testAttributeOnComputedProperty( ) {
4847
+ let input = """
4848
+ extension SectionContainer: ContentProviding where Section: ContentProviding {
4849
+ @_disfavoredOverload
4850
+ public var content: Section.Content {
4851
+ section.content
4852
+ }
4853
+ }
4854
+ """
4855
+
4856
+ let options = FormatOptions ( storedVarAttributes: . sameLine, computedVarAttributes: . prevLine)
4857
+ testFormatting ( for: input, rule: FormatRules . wrapAttributes, options: options)
4858
+ }
4859
+
4846
4860
// MARK: wrapEnumCases
4847
4861
4848
4862
func testMultilineEnumCases( ) {
You can’t perform that action at this time.
0 commit comments