Skip to content

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

Merged
timotheeguerin merged 5 commits into
microsoft:mainfrom
oha-4:fix/formatter-heritage-keyword-break
Jun 22, 2026
Merged

Keep is/extends inline for multi-argument template heritage#11011
timotheeguerin merged 5 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
Contributor

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: b211eb8

@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
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>
This reverts commit 051c04c, restoring the
regenerated crossLanguageVersion hash change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oha-4 oha-4 requested a review from alzimmermsft as a code owner June 22, 2026 05:31
@timotheeguerin timotheeguerin enabled auto-merge June 22, 2026 13:37
@timotheeguerin timotheeguerin added this pull request to the merge queue Jun 22, 2026
Merged via the queue into microsoft:main with commit ec37ca4 Jun 22, 2026
39 checks passed
@oha-4 oha-4 deleted the fix/formatter-heritage-keyword-break branch June 22, 2026 14:29
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.

3 participants