diff --git a/.chronus/changes/fix-formatter-decorator-op-augment-2026-04-29.md b/.chronus/changes/fix-formatter-decorator-op-augment-2026-04-29.md new file mode 100644 index 00000000000..6141e6d3d2f --- /dev/null +++ b/.chronus/changes/fix-formatter-decorator-op-augment-2026-04-29.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/compiler" +--- + +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. diff --git a/.chronus/changes/fix-formatter-decorator-op-augment-java-2026-04-29.md b/.chronus/changes/fix-formatter-decorator-op-augment-java-2026-04-29.md new file mode 100644 index 00000000000..fe19fae5172 --- /dev/null +++ b/.chronus/changes/fix-formatter-decorator-op-augment-java-2026-04-29.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-java" +--- + +Reformat augment decorator arguments in test files to match updated formatter style. diff --git a/packages/compiler/src/formatter/print/printer.ts b/packages/compiler/src/formatter/print/printer.ts index 0a104e021d7..bd04b45b895 100644 --- a/packages/compiler/src/formatter/print/printer.ts +++ b/packages/compiler/src/formatter/print/printer.ts @@ -565,7 +565,7 @@ function printAugmentDecoratorArgs( group([ indent( join(", ", [ - path.call(print, "targetType"), + [softline, path.call(print, "targetType")], ...path.map((arg) => [softline, print(arg)], "arguments"), ]), ), diff --git a/packages/compiler/test/formatter/formatter.test.ts b/packages/compiler/test/formatter/formatter.test.ts index 6be43cc8ded..28db76cf3b4 100644 --- a/packages/compiler/test/formatter/formatter.test.ts +++ b/packages/compiler/test/formatter/formatter.test.ts @@ -2483,10 +2483,24 @@ namespace Foo { @@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"); `, expected: ` -@@doc(Foo, +@@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" +); + `, + }); + }); + + it("break arguments per lines when decorator name is very long", async () => { + await assertFormat({ + code: ` +@@Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator(subscribe1); + `, + expected: ` +@@Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator.Some.Very.Long.Namespace.Decorator( + subscribe1 ); `, }); diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/external.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/external.tsp index 7d736c483fd..c7479347cab 100644 --- a/packages/http-client-java/generator/http-client-generator-test/tsp/external.tsp +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/external.tsp @@ -52,14 +52,16 @@ interface ExternalOp { postExternal(@body body: Body): Body; } -@@alternateType(CloudEventDataFormat, +@@alternateType( + CloudEventDataFormat, { identity: "com.azure.core.models.CloudEventDataFormat", }, "java" ); -@@alternateType(DayOfWeek, +@@alternateType( + DayOfWeek, { identity: "java.time.DayOfWeek", },