Skip to content

Commit 96f6e3e

Browse files
committed
Merge remote-tracking branch 'captainTorch/pretty-print'
2 parents afd4afb + 75edb48 commit 96f6e3e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,26 @@ function bind<F, L extends any[], R>(fn: (f: F, ...a: L) => R, first: F) {
4646

4747
export class DefaultThemeRenderContext {
4848
options: Options;
49+
private currentDepth = 0;
4950

5051
constructor(private theme: DefaultTheme, options: Options) {
5152
this.options = options;
5253
}
5354

5455
icons = icons;
5556

57+
getCurrentDepth(): number {
58+
return this.currentDepth;
59+
}
60+
61+
incrementCurrentDepth(): void {
62+
this.currentDepth++;
63+
}
64+
65+
decrementCurrentDepth(): void {
66+
this.currentDepth--;
67+
}
68+
5669
hook = (name: keyof RendererHooks) =>
5770
this.theme.owner.hooks.emit(name, this);
5871

src/lib/output/themes/default/partials/type.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import {
3+
DeclarationReflection,
34
LiteralType,
45
ProjectReflection,
56
ReferenceType,
@@ -66,6 +67,13 @@ function renderUniquePath(context: DefaultThemeRenderContext, reflection: Reflec
6667
</a>
6768
));
6869
}
70+
function includeIndentation(context: DefaultThemeRenderContext): JSX.Element {
71+
return context.getCurrentDepth() > 0 ? (
72+
<span>{new Array(context.getCurrentDepth() * 4).fill("\u00A0").join("")}</span>
73+
) : (
74+
<></>
75+
);
76+
}
6977

7078
// The type helper accepts an optional needsParens parameter that is checked
7179
// if an inner type may result in invalid output without them. For example:
@@ -277,8 +285,11 @@ const typeRenderers: {
277285
},
278286
reflection(context, type) {
279287
const members: JSX.Element[] = [];
288+
const children: DeclarationReflection[] = type.declaration.children || [];
289+
290+
if (children.length) context.incrementCurrentDepth();
280291

281-
for (const item of type.declaration.children || []) {
292+
for (const item of children) {
282293
if (item.getSignature && item.setSignature) {
283294
members.push(
284295
<>
@@ -359,14 +370,24 @@ const typeRenderers: {
359370
}
360371

361372
if (members.length) {
362-
const membersWithSeparators = members.flatMap((m) => [m, <span class="tsd-signature-symbol">; </span>]);
373+
const membersWithSeparators = members.flatMap((m) => [
374+
includeIndentation(context),
375+
m,
376+
<span class="tsd-signature-symbol">; </span>,
377+
<br></br>,
378+
]);
363379
membersWithSeparators.pop();
364380

381+
context.decrementCurrentDepth();
382+
365383
return (
366384
<>
367385
<span class="tsd-signature-symbol">{"{"} </span>
386+
<br></br>
368387
{membersWithSeparators}
369-
<span class="tsd-signature-symbol"> {"}"}</span>
388+
<br></br>
389+
{includeIndentation(context)}
390+
<span class="tsd-signature-symbol">{"}"}</span>
370391
</>
371392
);
372393
}

0 commit comments

Comments
 (0)