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

printer: supporting rewrapping #307

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6918,13 +6918,8 @@ fn parse_extends_or_implements<'a>(opts: ParseExtendsOrImplementsOptions<'a>, co
return items;
}

items.push_condition(conditions::new_line_if_hanging_space_otherwise(
conditions::NewLineIfHangingSpaceOtherwiseOptions {
start_info: opts.start_header_info,
end_info: None,
space_char: Some(conditions::if_above_width_or(context.config.indent_width, Signal::SpaceOrNewLine.into(), " ".into()).into()),
},
));
items.push_signal(Signal::PossibleNewLine);
items.push_condition(conditions::space_if_not_start_of_line(Some(" ".into())));
// the newline group will force it to put the extends or implements on a new line
Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on this comment, I guess the changes in the test snapshots aren't desirable then?

items.push_condition(conditions::indent_if_start_of_line(parser_helpers::new_line_group({
let mut items = PrintItems::new();
Expand Down
7 changes: 3 additions & 4 deletions tests/specs/declarations/class/ClassDeclaration_Header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ export class Test implements Testing, ThisOutABitHere<Tes, This, Out, With, A, L
}

[expect]
export class Test
implements
Testing,
ThisOutABitHere<Tes, This, Out, With, A, Long>
export class Test implements
Testing,
ThisOutABitHere<Tes, This, Out, With, A, Long>
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export class Test<TestingThisOut, WithVeryLong, TypeParameterList> extends Test
[expect]
export class Test<TestingThisOut, WithVeryLong,
TypeParameterList>
extends Test
implements Other
extends Test implements Other
{
}

Expand Down Expand Up @@ -63,9 +62,9 @@ export class Test implements Testing, ThisOutABitHere<Tes, This, Out, With, A, L
}

[expect]
export class Test
implements Testing,
ThisOutABitHere<Tes, This, Out, With, A, Long>
export class Test implements
Testing,
ThisOutABitHere<Tes, This, Out, With, A, Long>
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export interface Test<TestingThisOut, WithVeryLong, TypeParameterList> extends T

[expect]
export interface Test<TestingThisOut, WithVeryLong,
TypeParameterList>
extends Test
TypeParameterList> extends Test
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ test
test ? 1 : test ? 3 : 466666666666666666666;

[expect]
test
? 1
: test
test ? 1 : test
? 3
: 466666666666666666666;

Expand Down
24 changes: 24 additions & 0 deletions tests/specs/issues/issue0052.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
~~ lineWidth: 40 ~~
== avoids orphaning "extends" on its own line ==
export interface Preview extends Pick<BaseGuild, "id" | "name" | "icon" | "splash" | "discovery_splash" | "emojis" | "features" | "description"> {
approximate_member_count: number;
approximate_presence_count: number;
}

[expect]
export interface Preview extends
Pick<
BaseGuild,
| "id"
| "name"
| "icon"
| "splash"
| "discovery_splash"
| "emojis"
| "features"
| "description"
>
{
approximate_member_count: number;
approximate_presence_count: number;
}
7 changes: 3 additions & 4 deletions tests/specs/issues/old-repo/issue035.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ t(u, tbdstdddddbbSftt ? dddddmdd : testt);

[expect]
// skip format twice because preferSingleLine is false
t(u,
tbdstdddddbbSftt
? dddddmdd
: testt);
t(u, tbdstdddddbbSftt
? dddddmdd
: testt);
7 changes: 3 additions & 4 deletions tests/specs/issues/old-repo/issue035_PreferSingleLine.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
t(u, tbdstdddddbbSftt ? dddddmdd : testt);

[expect]
t(u,
tbdstdddddbbSftt
? dddddmdd
: testt);
t(u, tbdstdddddbbSftt
? dddddmdd
: testt);
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ function t([testing, thisOutWhere, itGoesOverTheLineWidth]) {
}

[expect]
function t(
[testing, thisOutWhere,
itGoesOverTheLineWidth],
) {
function t([
testing,
thisOutWhere,
itGoesOverTheLineWidth,
]) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ function test([testingThisOut, withSomeTextThatWillMakeIt]) {
}

[expect]
function test(
[
testingThisOut,
withSomeTextThatWillMakeIt,
],
) {
function test([
testingThisOut,
withSomeTextThatWillMakeIt,
]) {
}