diff --git a/src/app/components/generator/JsonFileView.tsx b/src/app/components/generator/JsonFileView.tsx index 19114bee..734c63c0 100644 --- a/src/app/components/generator/JsonFileView.tsx +++ b/src/app/components/generator/JsonFileView.tsx @@ -65,7 +65,7 @@ export function JsonFileView({ docAndNode, node }: JsonFileViewProps) { return type }, [resourceType, ctx]) - return
+ return
{(ctx && mcdocType) && }
} diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index a8ecc925..344c815e 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -28,6 +28,7 @@ type MakeEdit = (edit: (range: core.Range) => JsonNode | undefined) => void interface Props { type: Type optional?: boolean + excludeStrings?: string[] node: JsonNode | undefined ctx: McdocContext } @@ -48,12 +49,12 @@ export function McdocRoot({ type, node, ctx } : Props) { } -function Head({ type, optional, node, ctx }: Props) { +function Head({ type, optional, excludeStrings, node, ctx }: Props) { if (type.kind === 'string') { - return + return } if (type.kind === 'enum') { - return + return } if (isNumericType(type)) { return @@ -133,7 +134,7 @@ function Body({ type, optional, node, ctx }: Props) { const SPECIAL_UNSET = '__unset__' -function StringHead({ type, optional, node, ctx }: Props) { +function StringHead({ type, optional, excludeStrings, node, ctx }: Props) { const { locale } = useLocale() const value = (JsonStringNode.is(node) ? node.value : undefined)?.replaceAll('\n', '\\n') @@ -171,7 +172,8 @@ function StringHead({ type, optional, node, ctx }: Props) { const completions = useMemo(() => { return getValues(type, { ...ctx, offset: node?.range.start ?? 0 }) .filter(c => c.kind === 'string' && c.value !== 'THIS') - }, [type, node, ctx]) + .filter(c => !excludeStrings?.includes(c.value)) + }, [type, excludeStrings, node, ctx]) const datalistId = `mcdoc_completions_${hexId()}` @@ -211,7 +213,7 @@ function StringHead({ type, optional, node, ctx }: Props) { } -function EnumHead({ type, optional, node, ctx }: Props) { +function EnumHead({ type, optional, excludeStrings, node, ctx }: Props) { const { locale } = useLocale() const value = JsonStringNode.is(node) ? node.value : (node && JsonNumberNode.is(node)) ? Number(node.value.value) : undefined @@ -252,7 +254,7 @@ function EnumHead({ type, optional, node, ctx }: Props) { return @@ -653,8 +655,12 @@ function DynamicKey({ keyType, valueType, parent, ctx }: DynamicKeyProps) { }) }, [keyNode, ctx]) + const excludeStrings = useMemo(() => { + return parent.children.flatMap(pair => pair.key ? [pair.key.value] : []) + }, [parent]) + return <> - + }