This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
noncached.ts
52 lines (47 loc) · 1.69 KB
/
noncached.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { nbtDocs, NBTNode, ValueList } from "mc-nbt-paths";
import { SynchronousPromise } from "synchronous-promise";
import {
getLanguageService,
SchemaRequestService
} from "vscode-json-languageservice";
import { NBTDocs, NonCacheable } from "./types";
export function loadNBTDocs(): NBTDocs {
const nbtData = new Map<string, NBTNode | ValueList>();
Object.keys(nbtDocs).forEach(k => nbtData.set(k, nbtDocs[k]));
return nbtData;
}
const textComponentSchema =
"https://raw.githubusercontent.com/Levertion/minecraft-json-schema/master/java/shared/text_component.json";
export async function loadNonCached(): Promise<NonCacheable> {
const schemas: { [key: string]: string } = {
[textComponentSchema]: JSON.stringify(
// FIXME: parcel breaks require.resolve so we need to use plain require to get the correct path
// tslint:disable-next-line:no-require-imports
require("minecraft-json-schemas/java/shared/text_component")
)
};
const schemaRequestService: SchemaRequestService = url =>
schemas.hasOwnProperty(url)
? SynchronousPromise.resolve(schemas[url])
: SynchronousPromise.reject<string>(
`Schema at url ${url} not supported`
);
const jsonService = getLanguageService({
promiseConstructor: SynchronousPromise,
schemaRequestService
});
jsonService.configure({
allowComments: false,
schemas: [
{
fileMatch: ["text-component.json"],
uri: textComponentSchema
}
],
validate: true
});
return {
jsonService,
nbt_docs: loadNBTDocs()
};
}