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

Respect useLineBreaks for union/intersect toString #487

Merged

Conversation

JohnnyMorganz
Copy link
Contributor

This change makes Luau::toString() on a union or interesection type respect the useLineBreaks option in ToStringOption.

This mostly comes up in large function type intersections. For example for the type of game:GetService:

((self: ServiceProvider, service: "ABTestService") -> ABTestService) & ((self: ServiceProvider, service: "AdService") -> AdService) & ((self: ServiceProvider, service: "AnalyticsService") -> AnalyticsService) & ((self: ServiceProvider, service: "AnimationClipProvider") -> AnimationClipProvider) & ((self: ServiceProvider, service: "AnimationFromVideoCreatorService") -> AnimationFromVideoCreatorService) & ((self: ServiceProvider, service: "AnimationFromVideoCreatorStudioService") -> AnimationFromVideoCreatorStudioService)... <TRUNCATED>

Is now formatted as

((self: ServiceProvider, service: "ABTestService") -> ABTestService)
& ((self: ServiceProvider, service: "AdService") -> AdService)
& ((self: ServiceProvider, service: "AnalyticsService") -> AnalyticsService)
& ((self: ServiceProvider, service: "AnimationClipProvider") -> AnimationClipProvider)
& ((self: ServiceProvider, service: "AnimationFromVideoCreatorService") -> AnimationFromVideoCreatorService)
& ((self: ServiceProvider, service: "AnimationFromVideoCreatorStudioService") -> AnimationFromVideoCreatorStudioService)... <TRUNCATED>

Which makes this much nicer to read.
The equivalent is done for union operations.

Example when used in VSCode hover string

image

image

I realise that I think this toString operation is used internally for Studio's hover string. So I understand if this is undesirable behaviour / conflicts with studio internally (given that its the introduction of a lot more vertical space).

@JohnnyMorganz
Copy link
Contributor Author

I'm also interested in slightly modifying the output of TableTypeVar's when using useLineBreaks
Currently a newline is not inserted after the opening brace and before the first field (and similarly after the last field and before the closing brace).

Would you be happy accepting a change to this upstream? Again I realise its an introduction of a bit more vertical space. Will open a PR if so

Example of a before and after
local ATM: { Destroy: (self: any) -> (...any),
    __index: any,
    new: (base: any, store: any) -> (...any) }

image

will be modified to look like:

local ATM: {
    Destroy: (self: any) -> (...any),
    __index: any,
    new: (base: any, store: any) -> (...any)
}

Copy link
Collaborator

@andyfriesen andyfriesen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some exceedingly nitpicky formatting minutiae. No other problems.

Thanks!

Analysis/src/ToString.cpp Outdated Show resolved Hide resolved
Analysis/src/ToString.cpp Outdated Show resolved Hide resolved
tests/ToString.test.cpp Outdated Show resolved Hide resolved
tests/ToString.test.cpp Outdated Show resolved Hide resolved
Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
@andyfriesen andyfriesen merged commit f2191b9 into luau-lang:master May 17, 2022
@JohnnyMorganz JohnnyMorganz deleted the to-string-newline-union-intersect branch May 17, 2022 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants