show json in resolver source in debug

This commit is contained in:
2026-07-19 13:13:44 -04:00
parent 9011ef2271
commit aedeeb63be
2 changed files with 13 additions and 6 deletions

View File

@@ -1,5 +1,4 @@
[tools] [tools]
node = "latest"
"npm:vite" = "8.1.3" "npm:vite" = "8.1.3"
tinymist = "0.15.0" tinymist = "0.15.0"
typst = "0.15.0" typst = "0.15.0"

View File

@@ -157,7 +157,7 @@ export class BlockstateResolver {
if (!this.pending.has(id)) { if (!this.pending.has(id)) {
const [space, name] = id.split(':'); const [space, name] = id.split(':');
const url = `assets/${space}/blockstates/${name}.json`; const url = `/assets/${space}/blockstates/${name}.json`;
this.pending.set(id, fetch(url) this.pending.set(id, fetch(url)
.then(res => res.json()) .then(res => res.json())
@@ -165,8 +165,11 @@ export class BlockstateResolver {
const source = renderBlockstateResolver(data); const source = renderBlockstateResolver(data);
/** @type {ResolverFunction} */ /** @type {ResolverFunction} */
const resolver = new Function(`return function (state, hash) { ${source} } //# sourceURL=${url}`)(); const resolver = new Function(
import.meta.env.DEV
? `const raw_data = ${JSON.stringify(data)};\n\nreturn (state, hash) => { ${source} }\n//# sourceURL=${url}`
: `return (state, hash) => { ${source} }`
)();
this.resolvers.set(id, resolver); this.resolvers.set(id, resolver);
this.pending.delete(id); this.pending.delete(id);
@@ -178,10 +181,15 @@ export class BlockstateResolver {
this.resolvers.set(id, this.resolvers.get(':invalid')); this.resolvers.set(id, this.resolvers.get(':invalid'));
this.pending.delete(id); this.pending.delete(id);
console.log(`failed to resolve blockstate ${id}: ${reason}`); console.log(`failed to resolve blockstate ${id}: ${reason}`);
}) }));
);
} }
return this.resolvers.get(':pending'); return this.resolvers.get(':pending');
} }
resolve(id, pos, state) {
const resolver = this.getResolver(id);
const hash = pos[0] * 3.236 + pos[1] * 4.854 + pos[2] * 8.090;
return resolver(state, hash);
}
} }