Commit 482035c
Fix formatter blank line and over-indent for union template argument (#11010)
Fixes #11009
## Problem
When a `union` expression is used directly as one of multiple template
arguments and the argument list is long enough to wrap, `tsp format`
inserts a blank line before the union and indents its leading-`|`
variants one level deeper than the sibling arguments:
```tsp
model Picked
is PickProperties<
Sample,
| "alpha"
| "bravo"
...
>;
```
## Fix
`printTemplateParameters` already emits a `softline` + an `indent` level
before each argument in a multi-argument list. `printUnion` was *also*
emitting its own leading `line` + `indent` (+ `align(2)`), so the two
stacked, producing the blank line and the extra indentation level.
`printUnion` now detects when the union is a direct argument of a
multi-argument template reference (`isInMultiTemplateArgumentList`) and,
in that case, lets the surrounding argument list control the line break
and indentation. Result:
```tsp
model Picked
is PickProperties<
Sample,
| "alpha"
| "bravo"
...
>;
```
The standalone/value-position cases (e.g. `alias X = "a" | "b" | ...`)
and the single-template-argument (`shouldHug`) case are unchanged, since
there the surrounding context does not supply the line break/indent.
## Tests
- Added a regression test for the multi-argument case (#11009) and a
test pinning the single-argument behavior in `formatter.test.ts`.
- Reformatted two committed `http-client-java` test fixtures that
contained the buggy output (whitespace only; no semantic change).
- `pnpm prettier --check "**/*.tsp"`, formatter test suite, tsc, and
eslint all pass.
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>1 parent 4f8e319 commit 482035c
8 files changed
Lines changed: 108 additions & 18 deletions
File tree
- .chronus/changes
- packages
- compiler
- src/formatter/print
- test/formatter
- http-client-java/generator/http-client-generator-test
- src/main/resources/META-INF
- tsp
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1427 | 1427 | | |
1428 | 1428 | | |
1429 | 1429 | | |
1430 | | - | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
1434 | | - | |
1435 | | - | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
1436 | 1441 | | |
1437 | | - | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
1438 | 1454 | | |
1439 | 1455 | | |
1440 | 1456 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1972 | 1972 | | |
1973 | 1973 | | |
1974 | 1974 | | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
1975 | 2037 | | |
1976 | 2038 | | |
1977 | 2039 | | |
| |||
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 5 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
398 | 397 | | |
399 | 398 | | |
400 | 399 | | |
| |||
Lines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
0 commit comments