Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-java"
---

Reformat augment decorator arguments in test files to match updated formatter style.
2 changes: 1 addition & 1 deletion packages/compiler/src/formatter/print/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]),
),
Expand Down
16 changes: 15 additions & 1 deletion packages/compiler/test/formatter/formatter.test.ts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot I am not sure I want to force this decorator break, is it necessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's not necessary for the core fix. Reverted the operation decorator forced break in 1c33914. The PR now only fixes the augment decorator args asymmetric indentation (first arg hugging the paren while others were indented).

Original file line number Diff line number Diff line change
Expand Up @@ -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
);
`,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Loading