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

Lambda parameters dont line wrap #256

Closed
saik0 opened this issue Oct 11, 2017 · 4 comments
Closed

Lambda parameters dont line wrap #256

saik0 opened this issue Oct 11, 2017 · 4 comments

Comments

@saik0
Copy link

saik0 commented Oct 11, 2017

val barParams = ParameterSpec.builder("f",
        LambdaTypeName.get(parameters = generateSequence { Unit::class.asTypeName() }.take(20).toList(),
                           returnType = Unit::class.asTypeName()))
        .build()

val file = FileSpec.builder("", "Foo")
        .addFunction(FunSpec.builder("bar")
                .addParameter(barParams)
                .build())
        .build()

file.writeTo(System.out)

outputs:

fun bar(f: (Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit, Unit) -> Unit) {
}
@JakeWharton
Copy link
Member

This should trigger one-per-line parameters:

fun bar(
    f: ...
) {
}

but I don't think we'll worry about wrapping the actual lambda signature.

@saik0
Copy link
Author

saik0 commented Oct 11, 2017

Fair enough

@Egorand
Copy link
Collaborator

Egorand commented Oct 13, 2017

Currently parameter wrapping depends on the number of parameters and not on the length of the code, which is something we can improve. The difficult part is figuring out the length of the parameter code before it's emitted.

@swankjesse
Copy link
Member

Fixed.

package com.squareup.tacos

import kotlin.Unit

fun bar(f: (
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit,
    Unit
) -> Unit) {
}

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

4 participants