Re-add ohthetreesyoullgrow partner

This commit is contained in:
Misode
2024-10-31 06:41:30 +01:00
parent cf44c3236f
commit 68eb077c17
10 changed files with 104 additions and 106 deletions

View File

@@ -1,5 +1,5 @@
import * as core from '@spyglassmc/core'
import type { JsonNode, JsonPairNode } from '@spyglassmc/json'
import type { JsonNode } from '@spyglassmc/json'
import { JsonArrayNode, JsonObjectNode, JsonStringNode } from '@spyglassmc/json'
import { JsonStringOptions } from '@spyglassmc/json/lib/parser/string.js'
import type { ListType, McdocType, NumericRange, NumericType, PrimitiveArrayType, TupleType, UnionType } from '@spyglassmc/mcdoc'
@@ -226,22 +226,26 @@ export function isSelectRegistry(registry: string) {
return selectRegistries.has(registry)
}
export function simplifyType(type: McdocType, ctx: core.CheckerContext, pair?: JsonPairNode): SimplifiedMcdocType {
interface SimplifyNodeContext {
key?: JsonStringNode
parent?: JsonObjectNode
}
export function simplifyType(type: McdocType, ctx: core.CheckerContext, { key, parent }: SimplifyNodeContext = {}): SimplifiedMcdocType {
const simplifyNode: SimplifyValueNode<JsonNode | undefined> = {
entryNode: {
parent: pair && JsonObjectNode.is(pair?.parent) ? {
parent: parent ? {
entryNode: {
parent: undefined,
runtimeKey: undefined,
},
node: {
originalNode: pair.parent,
inferredType: inferType(pair.parent),
originalNode: parent,
inferredType: inferType(parent),
},
} : undefined,
runtimeKey: pair?.key ? {
originalNode: pair.key,
inferredType: inferType(pair.key),
runtimeKey: key ? {
originalNode: key,
inferredType: inferType(key),
} : undefined,
},
node: {

View File

@@ -474,7 +474,7 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: Props<SimplifiedSt
staticChilds.push(pair)
}
const child = pair?.value
const childType = simplifyType(field.type, ctx, pair)
const childType = simplifyType(field.type, ctx, { key: pair?.key, parent: node })
const makeFieldEdit: MakeEdit = (edit) => {
if (pair) {
makeEdit(() => {
@@ -562,7 +562,7 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: Props<SimplifiedSt
return
}
makeEdit((range) => {
const valueNode = getDefault(simplifyType(field.type, ctx, pair), range, ctx)
const valueNode = getDefault(simplifyType(field.type, ctx, { key: pair.key, parent: node }), range, ctx)
const newPair: core.PairNode<JsonStringNode, JsonNode> = {
type: 'pair',
range: keyNode.range,
@@ -600,7 +600,7 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: Props<SimplifiedSt
if (!field) {
return <></>
}
const childType = simplifyType(field.type, ctx, pair)
const childType = simplifyType(field.type, ctx, { key: pair.key, parent: node })
const makeFieldEdit: MakeEdit = (edit) => {
makeEdit(() => {
const newChild = edit(child?.range ?? core.Range.create(pair.range.end))

View File

@@ -7,7 +7,7 @@ import { DRAFT_PROJECT, useLocale, useProject, useVersion } from '../../contexts
import { useSpyglass, watchSpyglassUri } from '../../contexts/Spyglass.jsx'
import { AsyncCancel, useActiveTimeout, useAsync, useSearchParam } from '../../hooks/index.js'
import type { VersionId } from '../../services/index.js'
import { checkVersion, fetchPreset, fetchRegistries, getSnippet, shareSnippet } from '../../services/index.js'
import { checkVersion, fetchDependencyMcdoc, fetchPreset, fetchRegistries, getSnippet, shareSnippet } from '../../services/index.js'
import { Store } from '../../Store.js'
import { cleanUrl, genPath, safeJsonParse } from '../../Utils.js'
import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileRenaming, Footer, HasPreview, Octicon, PreviewPanel, ProjectCreation, ProjectDeletion, ProjectPanel, SearchList, SourcePanel, TextInput, Tree, VersionSwitcher } from '../index.js'
@@ -88,6 +88,11 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) {
if (text !== undefined) {
await service.writeFile(uri, text)
}
if (gen.dependency) {
const dependency = await fetchDependencyMcdoc(gen.dependency)
const dependencyUri = `file:///project/mcdoc/${gen.dependency}.mcdoc`
await service.getFile(dependencyUri, () => dependency)
}
// TODO: if text is undefined, set to generator's default
const docAndNode = await service.getFile(uri, () => '{}')
Analytics.setGenerator(gen.id)