Xcode 9 beta 5's code folding does not truncate functions with multi-line parameters consistently

Originator:jp
Number:rdar://33762193 Date Originated:07-Aug-2017 02:45 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 9 beta 5 (9M202q)
Classification:UI/Usability Reproducible:Always
 
Summary:
For example, this is a folded declaration:

func timestamp(_ timeZoneHour: Int = 0, ...}

And so is this:

@discardableResult func YamsAssertEqual(_ lhs: Any?, _ rhs: Any?, ...}

The curly braces aren’t balanced.

Xcode 8’s code folding avoided this issue by never folding a declaration, even if it was declared on multiple lines. It only ever folded the body.

Steps to Reproduce:
Fold the following function:

func timestamp(_ timeZoneHour: Int = 0,
               _ year: Int? = nil,
               _ month: Int? = nil,
               _ day: Int? = nil,
               _ hour: Int? = nil,
               _ minute: Int? = nil,
               _ second: Int? = nil,
               _ fraction: Double? = nil ) -> Date {
    let calendar = Calendar(identifier: .gregorian)
    let timeZone = TimeZone(secondsFromGMT: timeZoneHour * 60 * 60)
    #if os(Linux)
        let NSEC_PER_SEC = 1000000000
    #endif
    let nanosecond = fraction.map { Int($0 * Double(NSEC_PER_SEC)) }
    let datecomponents = DateComponents(calendar: calendar, timeZone: timeZone,
                          year: year, month: month, day: day,
                          hour: hour, minute: minute, second: second, nanosecond: nanosecond)
    // Using `DateComponents.date` causes crash on Linux
    guard let date = NSCalendar(identifier: .gregorian)?.date(from: datecomponents) else {
        fatalError("Never happen this")
    }
    return date
}

Expected Results:
The folded result should be one of the following:

func timestamp(_ timeZoneHour: Int = 0, ...) {...}

Or:

func timestamp(_ timeZoneHour: Int = 0,
               _ year: Int? = nil,
               _ month: Int? = nil,
               _ day: Int? = nil,
               _ hour: Int? = nil,
               _ minute: Int? = nil,
               _ second: Int? = nil,
               _ fraction: Double? = nil ) -> Date {...}

Actual Results:
The folded result is the following:

func timestamp(_ timeZoneHour: Int = 0, ...}

Version:
Xcode 9 beta 5 (9M202q)

Notes:
See attached gif of folding in action.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!