Skip to content

Commit f91c1be

Browse files
committed
Revert "Use Spyglass API to get vanilla-mcdoc symbols"
This reverts commit 63f9eed.
1 parent cb15e6c commit f91c1be

File tree

2 files changed

+19
-49
lines changed

2 files changed

+19
-49
lines changed

src/app/services/DataFetcher.ts

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ declare var __LATEST_VERSION__: string
1212
export const latestVersion = __LATEST_VERSION__ ?? ''
1313
const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta'
1414
const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball'
15+
const vanillaMcdocUrl = 'https://raw.githubusercontent.com/SpyglassMC/vanilla-mcdoc'
1516
const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'
1617
const fixesUrl = 'https://raw.githubusercontent.com/misode/mcfixes'
1718
const versionDiffUrl = 'https://mcmeta-diff.misode.workers.dev'
@@ -47,6 +48,19 @@ export function getVersionChecksum(versionId: VersionId) {
4748
return version.ref
4849
}
4950

51+
export interface VanillaMcdocSymbols {
52+
ref: string,
53+
mcdoc: Record<string, unknown>,
54+
'mcdoc/dispatcher': Record<string, Record<string, unknown>>,
55+
}
56+
export async function fetchVanillaMcdoc(): Promise<VanillaMcdocSymbols> {
57+
try {
58+
return cachedFetch<VanillaMcdocSymbols>(`${vanillaMcdocUrl}/generated/symbols.json`, { refresh: true })
59+
} catch (e) {
60+
throw new Error(`Error occured while fetching vanilla-mcdoc: ${message(e)}`)
61+
}
62+
}
63+
5064
export async function fetchDependencyMcdoc(dependency: string) {
5165
try {
5266
return cachedFetch(`/mcdoc/${dependency}.mcdoc`, { decode: res => res.text(), refresh: true })
@@ -490,41 +504,3 @@ async function applyPatches() {
490504
localStorage.setItem(CACHE_PATCH, i.toFixed())
491505
}
492506
}
493-
494-
export async function fetchWithCache(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
495-
const cache = await caches.open(CACHE_NAME)
496-
const request = new Request(input, init)
497-
const cachedResponse = await cache.match(request)
498-
const cachedEtag = cachedResponse?.headers.get('ETag')
499-
if (cachedEtag) {
500-
request.headers.set('If-None-Match', cachedEtag)
501-
}
502-
try {
503-
const response = await fetch(request)
504-
if (response.status === 304 && cachedResponse) {
505-
console.log(`[fetchWithCache] reusing cache for ${request.url}`)
506-
return cachedResponse
507-
} else if (!response.ok) {
508-
let message = response.statusText
509-
try {
510-
message = (await response.json()).message
511-
} catch (e) {}
512-
throw new TypeError(`${response.status} ${message}`)
513-
} else {
514-
try {
515-
await cache.put(request, response.clone())
516-
console.log(`[fetchWithCache] updated cache for ${request.url}`)
517-
} catch (e) {
518-
console.warn('[fetchWithCache] put cache', e)
519-
}
520-
return response
521-
}
522-
} catch (e) {
523-
console.warn('[fetchWithCache] fetch', e)
524-
if (cachedResponse) {
525-
console.log(`[fetchWithCache] falling back to cache for ${request.url}`)
526-
return cachedResponse
527-
}
528-
throw e
529-
}
530-
}

src/app/services/Spyglass.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { TextDocument } from 'vscode-languageserver-textdocument'
1212
import type { ConfigGenerator } from '../Config.js'
1313
import siteConfig from '../Config.js'
1414
import { computeIfAbsent, genPath } from '../Utils.js'
15-
import type { VersionMeta } from './DataFetcher.js'
16-
import { fetchBlockStates, fetchRegistries, fetchVersions, fetchWithCache, getVersionChecksum } from './DataFetcher.js'
15+
import type { VanillaMcdocSymbols, VersionMeta } from './DataFetcher.js'
16+
import { fetchBlockStates, fetchRegistries, fetchVanillaMcdoc, fetchVersions, getVersionChecksum } from './DataFetcher.js'
1717
import { IndexedDbFileSystem } from './FileSystem.js'
1818
import type { VersionId } from './Versions.js'
1919

20-
const SPYGLASS_API = 'https://api.spyglassmc.com'
21-
2220
export const CACHE_URI = 'file:///cache/'
2321
export const ROOT_URI = 'file:///root/'
2422
export const DEPENDENCY_URI = `${ROOT_URI}dependency/`
@@ -369,10 +367,10 @@ async function compressBall(files: [string, string][]): Promise<Uint8Array> {
369367
const initialize: core.ProjectInitializer = async (ctx) => {
370368
const { config, logger, meta, externals, cacheRoot } = ctx
371369

372-
const vanillaMcdocRes = await fetchWithCache(`${SPYGLASS_API}/vanilla-mcdoc/symbols`)
370+
const vanillaMcdoc = await fetchVanillaMcdoc()
373371
meta.registerSymbolRegistrar('vanilla-mcdoc', {
374-
checksum: vanillaMcdocRes.headers.get('ETag') ?? '',
375-
registrar: vanillaMcdocRegistrar(await vanillaMcdocRes.json()),
372+
checksum: vanillaMcdoc.ref,
373+
registrar: vanillaMcdocRegistrar(vanillaMcdoc),
376374
})
377375

378376
meta.registerDependencyProvider('@misode-mcdoc', async () => {
@@ -481,10 +479,6 @@ function registerAttributes(meta: core.MetaRegistry, release: ReleaseVersion, ve
481479

482480
const VanillaMcdocUri = 'mcdoc://vanilla-mcdoc/symbols.json'
483481

484-
interface VanillaMcdocSymbols {
485-
mcdoc: Record<string, unknown>,
486-
'mcdoc/dispatcher': Record<string, Record<string, unknown>>,
487-
}
488482
function vanillaMcdocRegistrar(vanillaMcdoc: VanillaMcdocSymbols): core.SymbolRegistrar {
489483
return (symbols) => {
490484
const start = performance.now()

0 commit comments

Comments
 (0)