Skip to content

Commit 99740ca

Browse files
Fix weird formatting on augment decorator args (#10556)
Augment decorator args broke asymmetrically (first arg hugging `(`, rest indented). ## Changes - **`printAugmentDecoratorArgs`**: Add `softline` before the first argument (targetType), matching `printCallLikeArgs` behavior for consistent indentation on break. ## Before/After ```tsp // Before: first arg hugs paren, closing paren on new line @@Some.Very.Long.Namespace.Decorator(subscribe1 ); // After: all args indent consistently @@Some.Very.Long.Namespace.Decorator( subscribe1 ); // Before: first arg hugs paren while rest are indented @@doc(Foo, "This is getting very very very long 1", "This is getting very very very long 2", "This is getting very very very long 3" ); // After: all args indent consistently @@doc( Foo, "This is getting very very very long 1", "This is getting very very very long 2", "This is getting very very very long 3" ); // Short lines remain inline @@doc(Foo, "This is some post doc"); ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
1 parent 483ce6d commit 99740ca

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/compiler"
5+
---
6+
7+
Fix formatting of decorators on operations and augment decorators. Decorators on operations now break to separate lines when the total line exceeds the print width. Augment decorator arguments are now consistently indented when the line breaks, matching TypeScript/prettier function call formatting.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-java"
5+
---
6+
7+
Reformat augment decorator arguments in test files to match updated formatter style.

packages/compiler/src/formatter/print/printer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ function printAugmentDecoratorArgs(
565565
group([
566566
indent(
567567
join(", ", [
568-
path.call(print, "targetType"),
568+
[softline, path.call(print, "targetType")],
569569
...path.map((arg) => [softline, print(arg)], "arguments"),
570570
]),
571571
),

packages/compiler/test/formatter/formatter.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2509,10 +2509,24 @@ namespace Foo {
25092509
@@doc(Foo, "This is getting very very very long 1", "This is getting very very very long 2", "This is getting very very very long 3");
25102510
`,
25112511
expected: `
2512-
@@doc(Foo,
2512+
@@doc(
2513+
Foo,
25132514
"This is getting very very very long 1",
25142515
"This is getting very very very long 2",
25152516
"This is getting very very very long 3"
2517+
);
2518+
`,
2519+
});
2520+
});
2521+
2522+
it("break arguments per lines when decorator name is very long", async () => {
2523+
await assertFormat({
2524+
code: `
2525+
@@Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator(subscribe1);
2526+
`,
2527+
expected: `
2528+
@@Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator(
2529+
subscribe1
25162530
);
25172531
`,
25182532
});

packages/http-client-java/generator/http-client-generator-test/tsp/external.tsp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ interface ExternalOp {
5252
postExternal(@body body: Body): Body;
5353
}
5454

55-
@@alternateType(CloudEventDataFormat,
55+
@@alternateType(
56+
CloudEventDataFormat,
5657
{
5758
identity: "com.azure.core.models.CloudEventDataFormat",
5859
},
5960
"java"
6061
);
6162

62-
@@alternateType(DayOfWeek,
63+
@@alternateType(
64+
DayOfWeek,
6365
{
6466
identity: "java.time.DayOfWeek",
6567
},

0 commit comments

Comments
 (0)