Skip to content

Keep is/extends inline for multi-argument template heritage#11011

Open
oha-4 wants to merge 3 commits into
microsoft:mainfrom
oha-4:fix/formatter-heritage-keyword-break
Open

Keep is/extends inline for multi-argument template heritage#11011
oha-4 wants to merge 3 commits into
microsoft:mainfrom
oha-4:fix/formatter-heritage-keyword-break

Conversation

@oha-4

@oha-4 oha-4 commented Jun 17, 2026

Copy link
Copy Markdown

Fixes the is-breaking part of #11009 (the blank-line/over-indent part is addressed separately in #11010).

Problem

When a model/scalar heritage clause (is X / extends X) references a template with multiple arguments, the formatter wrapped the keyword and the template reference in a single group(indent(...)). Prettier measures that group against the full flat width of the template argument list, so the group broke and pushed the keyword onto its own indented line — even when the declaration line itself was short:

model Picked
  is PickProperties<
    Sample,
    ...
  >;

Fix

printHeritageClause now keeps the keyword on the declaration line when the base is a template reference with multiple (breakable) arguments, and lets the template argument list control the line break:

model Picked is PickProperties<
  Sample,
  ...
>;

Single-argument (hugged) and non-template bases keep the previous behavior of breaking the keyword onto its own line when the declaration is too long.

Tests

  • Added regression tests for the multi-argument case on model is, model extends, and scalar extends in formatter.test.ts.
  • Reformatted one committed http-client-java test spec (arm-customization.tsp) that contained the old output (whitespace only, no semantic change).
  • Formatter test suite, eslint, tsc, and prettier --check "**/*.tsp" all pass locally.

Note: the crossLanguageVersion hash in the corresponding *_metadata.json is whitespace-sensitive; it will be updated from the RegenCheck output once CI runs.

🤖 Generated with Claude Code

@microsoft-github-policy-service microsoft-github-policy-service Bot added compiler:core Issues for @typespec/compiler emitter:client:java Issue for the Java client emitter: @typespec/http-client-java labels Jun 17, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11011

commit: 051c04c

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/http-client-java
Show changes

@typespec/compiler - fix ✏️

Keep the is/extends keyword on the declaration line when the base is a template reference with multiple arguments. The template argument list now controls the line breaking instead of the keyword being pushed onto its own indented line.

@typespec/http-client-java - internal ✏️

Reformat a test spec affected by the compiler formatter change keeping is/extends inline for multi-argument template references (whitespace only, no semantic change).

@oha-4 oha-4 force-pushed the fix/formatter-heritage-keyword-break branch from 0922558 to ce6a4b5 Compare June 17, 2026 15:49
A model/scalar heritage clause (`is X` / `extends X`) wrapped the keyword and
the template reference in one `group(indent(...))`. Prettier measures that
group against the full flat width of the template argument list, so it broke
and pushed the keyword onto its own indented line even when the declaration
line was short:

    model Picked
      is PickProperties<
        Sample,
        ...
      >;

`printHeritageClause` now keeps the keyword inline when the base is a template
reference with multiple (breakable) arguments, letting the argument list
control the line break:

    model Picked is PickProperties<
      Sample,
      ...
    >;

Single-argument and non-template bases keep breaking the keyword when the
declaration is too long.

Fixes the `is`-breaking part of microsoft#11009.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oha-4 oha-4 force-pushed the fix/formatter-heritage-keyword-break branch from ce6a4b5 to e3b7b82 Compare June 17, 2026 15:52
@microsoft-github-policy-service microsoft-github-policy-service Bot added the meta:website TypeSpec.io updates label Jun 17, 2026
Apply the new `is`/`extends` inline formatting (microsoft#11009) to committed artifacts
that the formatter now reformats: the http-client-java test spec
arm-customization.tsp and the 1.11 release-notes embedded example. Whitespace
only, no semantic change.

Also update the regenerated `crossLanguageVersion` hash in
azure-resourcemanager-armcustomization-generated_metadata.json, which is
whitespace-sensitive to the reformatted spec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oha-4 oha-4 force-pushed the fix/formatter-heritage-keyword-break branch from e3b7b82 to 95e7383 Compare June 17, 2026 20:45

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.

I'll ask the java team what is going on here if the CI still fails, but you shouldn't be changing those files in that pr

@oha-4 oha-4 Jun 19, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this, and for offering to check with the java team — much appreciated! I've reverted the *_metadata.json change so it's out of this PR. The arm-customization.tsp reformat stays since format:check enforces it.

For reference, earlier formatter PRs (#10556, #10558) reformatted these same Java test specs with no metadata change — crossLanguageVersion was added later (#10674), so reformatting had no hash impact back then. This PR is the first formatter change to hit that coupling.

Heads up: I expect RegenCheck to fail, because tcgc derives crossLanguageVersion from the raw .tsp source text (computeCrossLanguageVersion in package.ts), so the whitespace-only reformat changes the hash. Could you check with the java team on the right way to handle this?

Keep azure-resourcemanager-armcustomization-generated_metadata.json out of
this formatter PR as requested. The arm-customization.tsp reformat stays
(required by format:check); leaving the regenerated crossLanguageVersion
hash reverted lets CI surface the RegenCheck behavior for the java team.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler emitter:client:java Issue for the Java client emitter: @typespec/http-client-java meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants