From 9886155feef40b28dddb89457dc405f585666f18 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 30 Oct 2024 17:32:20 +0100 Subject: [PATCH] Manually filter out some fields due to probable spyglass bug --- src/app/components/generator/McdocRenderer.tsx | 18 ++++++++++++++++-- src/app/services/Spyglass.ts | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 77d28764..18081dbc 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -4,6 +4,7 @@ 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 { handleAttributes } from '@spyglassmc/mcdoc/lib/runtime/attribute/index.js' import type { McdocCheckerContext, SimplifiedEnum, SimplifiedMcdocType, SimplifiedMcdocTypeNoUnion, SimplifiedStructType, SimplifiedStructTypePairField, SimplifyValueNode } from '@spyglassmc/mcdoc/lib/runtime/checker/index.js' import { simplify } from '@spyglassmc/mcdoc/lib/runtime/checker/index.js' import { getValues } from '@spyglassmc/mcdoc/lib/runtime/completer/index.js' @@ -516,8 +517,21 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) { return <> } const type = node.typeDef?.kind === 'struct' ? node.typeDef : outerType - const staticFields = type.fields.filter(field => field.key.kind === 'literal') - const dynamicFields = type.fields.filter(field => field.key.kind !== 'literal') + // For some reason spyglass can include fields that haven't been filtered out in node.typeDef + const fields = type.fields.filter(field => { + let keep = true + handleAttributes(field.attributes, ctx, (handler, config) => { + if (!keep || !handler.filterElement) { + return + } + if (!handler.filterElement(config, ctx)) { + keep = false + } + }) + return keep + }) + const staticFields = fields.filter(field => field.key.kind === 'literal') + const dynamicFields = fields.filter(field => field.key.kind !== 'literal') const staticChilds: core.PairNode[] = [] return <> {staticFields.map(field => { diff --git a/src/app/services/Spyglass.ts b/src/app/services/Spyglass.ts index 7160bf19..b9115163 100644 --- a/src/app/services/Spyglass.ts +++ b/src/app/services/Spyglass.ts @@ -329,6 +329,9 @@ const initialize: core.ProjectInitializer = async (ctx) => { meta.registerFormatter('json:string', (node) => { return JSON.stringify(node.value) }) + meta.registerFormatter('error', () => { + return '' + }) return { loadedVersion: release } }