diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 44dff9d2..c37af4f0 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -2,6 +2,7 @@ import * as core from '@spyglassmc/core' import type { JsonNode } from '@spyglassmc/json' import * as json from '@spyglassmc/json' import { JsonArrayNode, JsonBooleanNode, JsonNumberNode, JsonObjectNode, JsonStringNode } from '@spyglassmc/json' +import { localeQuote } from '@spyglassmc/locales' import type { ListType, LiteralType, McdocType, NumericType, PrimitiveArrayType, StringType, TupleType, UnionType } from '@spyglassmc/mcdoc' import { TypeDefSymbolData } from '@spyglassmc/mcdoc/lib/binder/index.js' import type { McdocCheckerContext, SimplifiedEnum, SimplifiedMcdocType, SimplifiedMcdocTypeNoUnion, SimplifiedStructType, SimplifyValueNode } from '@spyglassmc/mcdoc/lib/runtime/checker/index.js' @@ -32,7 +33,7 @@ export function McdocRoot({ node, makeEdit, ctx } : Props) { return <>
- +
@@ -181,7 +182,7 @@ function EnumHead({ type, optional, node, makeEdit }: EnumHeadProps) { }) }, [type.enumKind, value, makeEdit]) - return onChangeValue((e.target as HTMLSelectElement).value)}> {(value === undefined || optional) && } {type.values.map(value => @@ -427,6 +428,7 @@ interface StructBodyProps extends Props { type: SimplifiedStructType } function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) { + const { locale } = useLocale() if (!JsonObjectNode.is(node)) { return <> } @@ -485,7 +487,8 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) { } return
- + {!field.optional && child === undefined && } + @@ -533,7 +536,7 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) { } return
- + @@ -582,7 +585,7 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) { } return
- +
@@ -593,18 +596,27 @@ function TupleBody({ type, node, makeEdit, ctx }: TupleBodyProps) { } interface ErrorsProps { + type: SimplifiedMcdocType node: JsonNode | undefined ctx: McdocContext } -function Errors({ node, ctx }: ErrorsProps) { +function Errors({ type, node, ctx }: ErrorsProps) { const errors = useMemo(() => { if (node === undefined) { return [] } return ctx.err.errors + // Get all errors inside the current node .filter(e => core.Range.containsRange(node.range, e.range, true)) + // Unless they are inside a child node .filter(e => !node.children?.some(c => (c.type === 'item' || c.type === 'pair') && core.Range.containsRange(c.range, e.range, true))) - }, [node, ctx]) + // Filter out "Missing key" errors + .filter(e => !(core.Range.length(e.range) === 1 && (type.kind === 'struct' || (type.kind === 'union' && findSelectedMember(type, node).kind === 'struct')))) + }, [type, node, ctx]) + + if (errors.length > 0) { + console.log(type, node, errors) + } return <> {errors.map(e => )} diff --git a/src/app/services/Spyglass.ts b/src/app/services/Spyglass.ts index 177528e4..371104df 100644 --- a/src/app/services/Spyglass.ts +++ b/src/app/services/Spyglass.ts @@ -197,6 +197,13 @@ export class SpyglassService { }, lint: { idOmitDefaultNamespace: false, + undeclaredSymbol: [ + { + if: { category: ['bossbar', 'objective', 'team'] }, + then: { declare: 'block' }, + }, + ...core.VanillaConfig.lint.undeclaredSymbol as any[], + ], }, }), initializers: [mcdoc.initialize, initialize], diff --git a/src/locales/en.json b/src/locales/en.json index 2efe10f6..1be96c3e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -160,6 +160,7 @@ "layer.vegetation": "Humidity", "learn_on_the_wiki": "Learn on the wiki", "loading": "Loading...", + "missing_key": "Missing required key %0%", "mode.3d": "3D", "mode.side": "Side", "mode.top": "Top",