Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem parsing generic function parameters when function split over multiple lines #896

Closed
mwoollard opened this issue Oct 20, 2017 · 6 comments

Comments

@mwoollard
Copy link

When documenting the following definition the following is parsed fine:

public protocol VehiclePositionManager {
    func positions(for region: Observable<LocationRegion?>, stopId: String?, routeIds: [String]?) -> Observable<[VehiclePositionType]>
    
}

jazzy1

But if the function is broken over several lines it gets truncated in the docs:

public protocol VehiclePositionManager {
    func positions(for region: Observable<LocationRegion?>,
                   stopId: String?, 
                   routeIds: [String]?) -> Observable<[VehiclePositionType]>
}

jazzy2

This problem doesn't appear to happen if the function parameters don't include any generic definitions.

Thanks
Mark

@johnfairh
Copy link
Collaborator

I think this happens for all multi-line function declarations inside protocols, the generic types look like a coincidence.

@johnfairh
Copy link
Collaborator

This turns out to be tough to completely fix. SourceKitten normally uses the 'body offset' key to know when the declaration ends, which is absent for protocol methods. A rule like for functions without 'body offset', use 'length' works correctly in the example here, but it turns out 'length' does not include any where clause meaning that always gets dropped, even if all on one line. Not sure if that is an improvement.

With PR #902 as-is, these function definitions show up entirely but all on one long line, which is correct but ugly. Could add a ghastly rule there, assuming the sourcekitten change [ie. respect multi-line but always drop where clause], to say "if protocol func has multiple lines then use the multi-line version, unless it also has generic parameter constraints in which case use the all-on-one-line version".

@johnfairh
Copy link
Collaborator

I fixed the underlying Swift problem with where so this issue should be fixable for real in 4.2/5.0 with a SourceKitten tweak.

@johnfairh
Copy link
Collaborator

Jazzy has a workaround for this now, prints the function on a single line. Trying to do the 'real' fix found another Swift bug causing a separate regression: will have to wait another cycle.

@mwoollard
Copy link
Author

OK thanks for the update

@johnfairh
Copy link
Collaborator

Fixed in master (with a Swift 5.1+ project)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants