Skip to content

WIP: little tweak, softline in variable initialization#222

Closed
Hawkurane wants to merge 4 commits intojhipster:masterfrom
Hawkurane:softline_in_initialiation
Closed

WIP: little tweak, softline in variable initialization#222
Hawkurane wants to merge 4 commits intojhipster:masterfrom
Hawkurane:softline_in_initialiation

Conversation

@Hawkurane
Copy link
Contributor

This adds a soft line when initializing a variable. This is get closer to PrettierJS behaviour. See #218.

@Hawkurane
Copy link
Contributor Author

Currently, the java printer is not able to break a variable declaration into two lines such as:

private static int some_variable = 
    some_random_value;

I've tried to use a few tricks to make it doable but I can't seem to be able to handle the priority of grouping.

// Should be
private static int some_variable = some_random_function(
    value1,
    value2
);

// This breaks the line when we are using a binary operator instead of breaking the argument list.
private static int some_variable =
    some_random_function(value1, value2) + "literal_value";

// What it does no matter what
private static int some_variable =
    some_random_function(value1, value2);

This suits PrettierJS in this specific case but overrides many other cases (see 2nd example)

@clementdessoude
Copy link
Contributor

The issue is that you cannot tell which group should break in priority with the prettier API : see https://github.com/prettier/prettier/blob/master/commands.md#group

Groups are usually nested, and the printer will try to fit everything on one line, but if it doesn't fit it will break the outermost group first and try again. It will continue breaking groups until everything fits (or there are no more groups to break).

@Hawkurane
Copy link
Contributor Author

Indeed it looks like the outermost will always break in priority.
In our case it seems to vary, sometimes the innermost breaks first...

Copy link
Contributor

Choose a reason for hiding this comment

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

lets not merge commented out code 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is still WIP because I am still trying to fix 2 bugs and I still need the printing.

@clementdessoude clementdessoude changed the title little tweak, softline in variable initialization WIP: little tweak, softline in variable initialization Jun 25, 2019
@Hawkurane
Copy link
Contributor Author

I am closing this PR as this is currently too difficult. I will rework on this at a later date with smaller PR's because this one is dependent of others

@Hawkurane Hawkurane closed this Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants