From b66b53ceaab1bc0f5e55f2ceb0dc8885c9798d38 Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 24 Oct 2024 06:07:12 +0200 Subject: [PATCH] Show doc comments --- .../components/generator/McdocRenderer.tsx | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index c382bfa0..32117c79 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -33,6 +33,7 @@ export function McdocRoot({ node, makeEdit, ctx } : Props) { return <>
+
@@ -170,7 +171,7 @@ function EnumHead({ type, optional, node, makeEdit }: EnumHeadProps) { return } @@ -478,6 +479,7 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) { return
+
@@ -526,6 +528,7 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) { return
+ @@ -555,7 +558,8 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) { } return <> {type.items.map((item, index) => { - const child = node?.children?.[index]?.value + const itemNode = node?.children?.[index] + const child = itemNode?.value const itemType = simplifyType(item, ctx) const makeItemEdit: MakeEdit = (edit) => { makeEdit(() => { @@ -574,6 +578,7 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) { return
+
@@ -614,6 +619,27 @@ function ErrorIndicator({ error }: ErrorIndicatorProps) {
} +interface DocsProps { + hover: string | undefined +} +function Docs({ hover }: DocsProps) { + if (hover === undefined) { + return <> + } + const descStart = hover.indexOf('```', hover.indexOf('```') + 3) + 4 + const desc = hover.substring(descStart).trim().replaceAll('`', '') + if (desc.length === 0) { + return <> + } + + const [active, setActive] = useFocus() + + return
setActive()}> + {Octicon.info} + {desc} +
+} + function getDefault(type: McdocType, range: core.Range, ctx: McdocContext): JsonNode { if (type.kind === 'string') { return JsonStringNode.mock(range)