diff --git a/src/app/services/DataFetcher.ts b/src/app/services/DataFetcher.ts index eeaf77ea..5b31ad16 100644 --- a/src/app/services/DataFetcher.ts +++ b/src/app/services/DataFetcher.ts @@ -12,11 +12,11 @@ declare var __LATEST_VERSION__: string export const latestVersion = __LATEST_VERSION__ ?? '' const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta' const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball' +const vanillaMcdocUrl = 'https://raw.githubusercontent.com/SpyglassMC/vanilla-mcdoc' const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes' const fixesUrl = 'https://raw.githubusercontent.com/misode/mcfixes' const versionDiffUrl = 'https://mcmeta-diff.misode.workers.dev' const whatsNewUrl = 'https://whats-new.misode.workers.dev' -const vanillaMcdocUrl = 'https://proxy.misode.workers.dev/mcdoc' type McmetaTypes = 'summary' | 'data' | 'data-json' | 'assets' | 'assets-json' | 'registries' | 'atlas' @@ -48,9 +48,14 @@ export function getVersionChecksum(versionId: VersionId) { return version.ref } -export async function fetchVanillaMcdoc() { +export interface VanillaMcdocSymbols { + ref: string, + mcdoc: Record, + 'mcdoc/dispatcher': Record>, +} +export async function fetchVanillaMcdoc(): Promise { try { - return cachedFetch(vanillaMcdocUrl, { decode: res => res.arrayBuffer(), refresh: true }) + return cachedFetch(`${vanillaMcdocUrl}/generated/symbols.json`, { refresh: true }) } catch (e) { throw new Error(`Error occured while fetching vanilla-mcdoc: ${message(e)}`) } diff --git a/src/app/services/Spyglass.ts b/src/app/services/Spyglass.ts index ae9335e2..16e9c19b 100644 --- a/src/app/services/Spyglass.ts +++ b/src/app/services/Spyglass.ts @@ -12,7 +12,7 @@ import { TextDocument } from 'vscode-languageserver-textdocument' import type { ConfigGenerator } from '../Config.js' import siteConfig from '../Config.js' import { computeIfAbsent, genPath } from '../Utils.js' -import type { VersionMeta } from './DataFetcher.js' +import type { VanillaMcdocSymbols, VersionMeta } from './DataFetcher.js' import { fetchBlockStates, fetchRegistries, fetchVanillaMcdoc, fetchVersions, getVersionChecksum } from './DataFetcher.js' import { IndexedDbFileSystem } from './FileSystem.js' import type { VersionId } from './Versions.js' @@ -302,7 +302,7 @@ export class SpyglassService { defaultConfig: core.ConfigService.merge(core.VanillaConfig, { env: { gameVersion: version.dynamic ? version.id : version.ref, - dependencies: ['@vanilla-mcdoc', '@misode-mcdoc'], + dependencies: ['@misode-mcdoc'], customResources: { text_component: { category: 'text_component', @@ -366,11 +366,10 @@ async function compressBall(files: [string, string][]): Promise { const initialize: core.ProjectInitializer = async (ctx) => { const { config, logger, meta, externals, cacheRoot } = ctx - meta.registerDependencyProvider('@vanilla-mcdoc', async () => { - const uri: string = new core.Uri('downloads/vanilla-mcdoc.tar.gz', cacheRoot).toString() - const buffer = await fetchVanillaMcdoc() - await core.fileUtil.writeFile(externals, uri, new Uint8Array(buffer)) - return { info: { startDepth: 1 }, uri } + const vanillaMcdoc = await fetchVanillaMcdoc() + meta.registerSymbolRegistrar('vanilla-mcdoc', { + checksum: vanillaMcdoc.ref, + registrar: vanillaMcdocRegistrar(vanillaMcdoc), }) meta.registerDependencyProvider('@misode-mcdoc', async () => { @@ -476,3 +475,31 @@ function registerAttributes(meta: core.MetaRegistry, release: ReleaseVersion, ve }, }) } + +const VanillaMcdocUri = 'mcdoc://vanilla-mcdoc/symbols.json' + +function vanillaMcdocRegistrar(vanillaMcdoc: VanillaMcdocSymbols): core.SymbolRegistrar { + return (symbols) => { + const start = performance.now() + for (const [id, typeDef] of Object.entries(vanillaMcdoc.mcdoc)) { + symbols.query(VanillaMcdocUri, 'mcdoc', id).enter({ + data: { data: { typeDef } }, + usage: { type: 'declaration' }, + }) + } + for (const [dispatcher, ids] of Object.entries(vanillaMcdoc['mcdoc/dispatcher'])) { + symbols.query(VanillaMcdocUri, 'mcdoc/dispatcher', dispatcher) + .enter({ usage: { type: 'declaration' } }) + .onEach(Object.entries(ids), ([id, typeDef], query) => { + query.member(id, (memberQuery) => { + memberQuery.enter({ + data: { data: { typeDef } }, + usage: { type: 'declaration' }, + }) + }) + }) + } + const duration = performance.now() - start + console.log(`[vanillaMcdocRegistrar] Done in ${duration}ms`) + } +}