@spyglassmc/mcdoc 0.1.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,358 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.module_ = void 0;
4
- // import type * as core from '@spyglassmc/core'
5
- // import type { Checker, RangeLike, Symbol, SymbolQuery } from '@spyglassmc/core'
6
- // import { ErrorSeverity, Range, ResourceLocationNode, SymbolPath, SymbolUtil } from '@spyglassmc/core'
7
- // import { localeQuote, localize } from '@spyglassmc/locales'
8
- // import type { Segments } from '../binder'
9
- // import { identifierToSeg, segToIdentifier } from '../binder'
10
- // import type { DispatchStatementNode, IdentPathToken, InjectClauseNode, MainNode, UseStatementNode } from '../node'
11
- // import { CompoundFieldNode, EnumFieldNode, EnumNode, ExtendableRootRegistryMap, StructNode } from '../node'
12
- // import type { CheckerContext } from './CheckerContext'
13
- const module_ = async (node, ctx) => {
14
- // const modSeg = uriToSeg(ctx.doc.uri, ctx)
15
- // if (modSeg === undefined) {
16
- // ctx.err.report(localize('mcdoc.checker.entry.undefined-mod-seg'), 0, ErrorSeverity.Warning)
17
- // return
18
- // } else if (modSeg.length === 0) {
19
- // ctx.err.report(localize('mcdoc.checker.entry.empty-mod-seg'), 0, ErrorSeverity.Warning)
20
- // }
21
- // const modIdentifier = segToIdentifier(modSeg)
22
- // const modSymbol = ctx.symbols.query(ctx.doc, 'mcdoc', modIdentifier).symbol!
23
- // const hoistingNodes: (StructNode | EnumNode | ModuleDeclarationNode | UseStatementNode)[] = []
24
- // const checkingNodes: (StructNode | EnumNode | DispatchStatementNode | InjectClauseNode)[] = []
25
- // for (const childNode of node.children) {
26
- // switch (childNode.type) {
27
- // case 'mcdoc:struct':
28
- // hoistingNodes.push(childNode)
29
- // checkingNodes.push(childNode)
30
- // break
31
- // case 'mcdoc:describes_clause':
32
- // checkingNodes.push(childNode)
33
- // break
34
- // case 'mcdoc:enum':
35
- // hoistingNodes.push(childNode)
36
- // checkingNodes.push(childNode)
37
- // break
38
- // case 'mcdoc:inject_clause':
39
- // checkingNodes.push(childNode)
40
- // break
41
- // case 'mcdoc:module_declaration':
42
- // hoistingNodes.push(childNode)
43
- // break
44
- // case 'mcdoc:use_statement':
45
- // hoistingNodes.push(childNode)
46
- // break
47
- // case 'comment':
48
- // default:
49
- // break
50
- // }
51
- // }
52
- // const mcdocCtx: CheckerContext = {
53
- // ...ctx,
54
- // modIdentifier,
55
- // modSeg,
56
- // modSymbol,
57
- // }
58
- // // Hoisting declarations.
59
- // for (const childNode of hoistingNodes) {
60
- // switch (childNode.type) {
61
- // case 'mcdoc:struct':
62
- // compoundDefinitionHoisting(childNode, mcdocCtx)
63
- // break
64
- // case 'mcdoc:enum':
65
- // enumDefinitionHoisting(childNode, mcdocCtx)
66
- // break
67
- // case 'mcdoc:module_declaration':
68
- // moduleDeclaration(childNode, mcdocCtx)
69
- // break
70
- // case 'mcdoc:use_statement':
71
- // await useClause(childNode, mcdocCtx)
72
- // break
73
- // }
74
- // }
75
- // // Actual checking.
76
- // for (const childNode of checkingNodes) {
77
- // switch (childNode.type) {
78
- // case 'mcdoc:struct':
79
- // await compoundDefinition(childNode, mcdocCtx)
80
- // break
81
- // case 'mcdoc:enum':
82
- // enumDefinition(childNode, mcdocCtx)
83
- // break
84
- // case 'mcdoc:describes_clause':
85
- // await dispatchStatement(childNode, mcdocCtx)
86
- // break
87
- // case 'mcdoc:inject_clause':
88
- // await injectClause(childNode, mcdocCtx)
89
- // break
90
- // }
91
- // }
92
- };
93
- exports.module_ = module_;
94
- // async function compoundFields<N extends { fields: CompoundFieldNode[] }>(definitionQuery: core.SymbolQuery, node: N, ctx: CheckerContext) {
95
- // const promises: Promise<void>[] = []
96
- // definitionQuery.onEach(node.fields, field => {
97
- // promises.push(new Promise(resolve => {
98
- // definitionQuery.member(field.key.value, member => member
99
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, field.key))
100
- // .else(async () => {
101
- // const data = await CompoundFieldNode.toSymbolData(field, async n => (await resolveIdentPath(n, ctx))?.symbol)
102
- // member.enter({
103
- // data: { data, desc: field.doc.value, subcategory: 'compound_key' },
104
- // usage: { type: 'definition', node: field.key, fullRange: field },
105
- // })
106
- // resolve()
107
- // })
108
- // )
109
- // }))
110
- // })
111
- // return Promise.allSettled(promises)
112
- // }
113
- // const compoundDefinition = async (node: StructNode, ctx: CheckerContext): Promise<void> => {
114
- // const definitionQuery = ctx.symbols.query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
115
- // if (!definitionQuery.symbol) {
116
- // return
117
- // }
118
- // const data = await StructNode.toSymbolData(node, async n => (await resolveIdentPath(n, ctx))?.symbol)
119
- // definitionQuery.amend({ data: { data } })
120
- // await compoundFields(definitionQuery, node, ctx)
121
- // }
122
- // const compoundDefinitionHoisting = (node: StructNode, ctx: CheckerContext): void => {
123
- // if (!node.identifier.value) {
124
- // return
125
- // }
126
- // ctx.symbols
127
- // .query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
128
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, node.identifier))
129
- // .elseEnter({
130
- // data: {
131
- // desc: node.doc.value,
132
- // subcategory: 'compound',
133
- // },
134
- // usage: {
135
- // type: 'definition',
136
- // node: node.identifier,
137
- // fullRange: node,
138
- // },
139
- // })
140
- // }
141
- // const dispatchStatement = async (node: DispatchStatementNode, ctx: CheckerContext): Promise<void> => {
142
- // const registry = ResourceLocationNode.toString(node.registry, 'full')
143
- // if (!(registry in ExtendableRootRegistryMap)) {
144
- // return
145
- // }
146
- // const describerSymbol = await resolveIdentPath(node.path, ctx)
147
- // const category = ExtendableRootRegistryMap[registry as keyof typeof ExtendableRootRegistryMap]
148
- // const objects = node.objects ? node.objects.map(v => ResourceLocationNode.toString(v, 'full')) : ['@default']
149
- // ctx.symbols
150
- // .query(ctx.doc, 'mcdoc/description', category)
151
- // .enter({})
152
- // .onEach(objects, (object, query) => {
153
- // query.member(object, member => member
154
- // .enter({
155
- // data: {
156
- // relations: {
157
- // describedBy: SymbolPath.fromSymbol(describerSymbol?.symbol),
158
- // },
159
- // },
160
- // usage: { type: 'definition', range: node },
161
- // })
162
- // )
163
- // })
164
- // }
165
- // function enumFields<N extends { fields: EnumFieldNode[] }>(definitionQuery: core.SymbolQuery, node: N, ctx: CheckerContext) {
166
- // definitionQuery.onEach(node.fields, field => {
167
- // definitionQuery.member(field.key.value, member => member
168
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, field.key))
169
- // .else(() => {
170
- // const data = EnumFieldNode.toSymbolData(field)
171
- // member.enter({
172
- // data: { data, desc: field.doc.value, subcategory: 'enum_key' },
173
- // usage: { type: 'definition', node: field.key, fullRange: field },
174
- // })
175
- // })
176
- // )
177
- // })
178
- // }
179
- // const enumDefinition = (node: EnumNode, ctx: CheckerContext): void => {
180
- // const definitionQuery = ctx.symbols.query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
181
- // if (!definitionQuery.symbol) {
182
- // return
183
- // }
184
- // const data = EnumNode.toSymbolData(node)
185
- // definitionQuery.amend({ data: { data } })
186
- // enumFields(definitionQuery, node, ctx)
187
- // }
188
- // const enumDefinitionHoisting = (node: EnumNode, ctx: CheckerContext): void => {
189
- // if (!node.identifier.value) {
190
- // return
191
- // }
192
- // ctx.symbols
193
- // .query(ctx.doc, 'mcdoc', ctx.modIdentifier, node.identifier.value)
194
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, node.identifier))
195
- // .elseEnter({
196
- // data: {
197
- // desc: node.doc.value,
198
- // subcategory: 'enum',
199
- // },
200
- // usage: {
201
- // type: 'definition',
202
- // node: node.identifier,
203
- // fullRange: node,
204
- // },
205
- // })
206
- // }
207
- // const injectClause = async (node: InjectClauseNode, ctx: CheckerContext): Promise<void> => {
208
- // if (!node.def) {
209
- // return
210
- // }
211
- // const injectedQuery = await resolveIdentPath(node.def.path, ctx)
212
- // if (!injectedQuery?.symbol) {
213
- // return
214
- // }
215
- // if (!(
216
- // (node.def?.type === 'mcdoc:inject_clause/compound' && injectedQuery.symbol.subcategory === 'compound') ||
217
- // (node.def?.type === 'mcdoc:inject_clause/enum' && injectedQuery.symbol.subcategory === 'enum')
218
- // )) {
219
- // const target = localize(`mcdoc.node.${injectedQuery.symbol.subcategory === 'enum' ? 'enum-definition' : 'compound-definition'}`)
220
- // const injection = localize(`mcdoc.node.${node.def?.type === 'mcdoc:inject_clause/enum' ? 'enum-definition' : 'compound-definition'}`)
221
- // ctx.err.report(localize('mcdoc.checker.inject-clause.unmatched-injection', target, injection), node.def.path)
222
- // return
223
- // }
224
- // if (node.def?.type === 'mcdoc:inject_clause/compound') {
225
- // await compoundFields(injectedQuery, node.def, ctx)
226
- // } else if (node.def?.type === 'mcdoc:inject_clause/enum') {
227
- // enumFields(injectedQuery, node.def, ctx)
228
- // }
229
- // }
230
- // const moduleDeclaration = (node: ModuleDeclarationNode, ctx: CheckerContext): void => {
231
- // if (node.identifier.value.length) {
232
- // const declaredSeg = [...ctx.modSeg, node.identifier.value]
233
- // const declaredIdentifier = segToIdentifier(declaredSeg)
234
- // ctx.symbols
235
- // .query(ctx.doc, 'mcdoc', declaredIdentifier)
236
- // .ifUnknown(() => ctx.err.report(
237
- // localize('mcdoc.checker.module-declaration.non-existent', localeQuote(declaredIdentifier)),
238
- // node.identifier
239
- // ))
240
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.module-declaration.duplicated', ctx, symbol, node.identifier))
241
- // .elseEnter({
242
- // usage: {
243
- // type: 'declaration',
244
- // node: node.identifier,
245
- // fullRange: node,
246
- // },
247
- // })
248
- // }
249
- // }
250
- // const useClause = async (node: UseStatementNode, ctx: CheckerContext): Promise<void> => {
251
- // const usedSymbol = (await resolveIdentPath(node.path, ctx))?.symbol
252
- // if (usedSymbol) {
253
- // const lastToken = node.path.children[node.path.children.length - 1]
254
- // ctx.symbols
255
- // .query({ doc: ctx.doc, node }, 'mcdoc', ctx.modIdentifier, usedSymbol.identifier)
256
- // .ifDeclared(symbol => reportDuplicatedDeclaration('mcdoc.checker.duplicated-identifier', ctx, symbol, lastToken))
257
- // .elseEnter({
258
- // data: {
259
- // relations: {
260
- // aliasOf: { category: 'mcdoc', path: usedSymbol.path },
261
- // },
262
- // },
263
- // usage: {
264
- // type: 'declaration',
265
- // node: lastToken,
266
- // fullRange: node,
267
- // ...node.isExport ? {} : { visibility: SymbolVisibility.File },
268
- // },
269
- // })
270
- // }
271
- // }
272
- // function reportDuplicatedDeclaration(localeString: string, ctx: CheckerContext, symbol: Symbol, range: RangeLike) {
273
- // ctx.err.report(
274
- // localize(localeString, localeQuote(symbol.identifier)),
275
- // range, ErrorSeverity.Warning,
276
- // {
277
- // related: [{
278
- // location: SymbolUtil.getDeclaredLocation(symbol) as core.Location,
279
- // message: localize(`${localeString}.related`, localeQuote(symbol.identifier)),
280
- // }],
281
- // }
282
- // )
283
- // }
284
- // function uriToSeg(uri: string, ctx: core.CheckerContext): Segments | undefined {
285
- // const identifier = Object
286
- // .keys(ctx.symbols.global.mcdoc ?? {})
287
- // .find(identifier => {
288
- // const symbol = ctx.symbols.global.mcdoc![identifier]!
289
- // return symbol.subcategory === 'module' && symbol.implementation?.some(loc => loc.uri === uri)
290
- // })
291
- // return identifier ? identifierToSeg(identifier) : undefined
292
- // }
293
- // function segToUri(seg: Segments, ctx: core.CheckerContext): string | undefined {
294
- // const identifier = segToIdentifier(seg)
295
- // return ctx.symbols.global.mcdoc?.[identifier]?.implementation?.[0]?.uri
296
- // }
297
- // /**
298
- // * @returns The actual symbol being used/imported from another module.
299
- // */
300
- // async function resolveIdentPath(identPath: IdentPathToken, ctx: CheckerContext): Promise<SymbolQuery | undefined> {
301
- // const targetSeg = identPath.fromGlobalRoot ? [] : [...ctx.modSeg]
302
- // for (const [i, token] of identPath.children.entries()) {
303
- // if (i < identPath.children.length - 1) {
304
- // // Referencing to a module.
305
- // // Resolve this token.
306
- // if (token.value === 'super') {
307
- // if (targetSeg.length === 0) {
308
- // ctx.err.report(localize('mcdoc.checker.ident-path.super-from-root'), Range.span(token, identPath))
309
- // return undefined
310
- // }
311
- // targetSeg.pop()
312
- // } else {
313
- // targetSeg.push(token.value)
314
- // }
315
- // ctx.symbols
316
- // .query(ctx.doc, 'mcdoc', segToIdentifier(targetSeg))
317
- // .amend({
318
- // usage: {
319
- // type: 'reference',
320
- // node: token,
321
- // skipRenaming: token.value === 'super',
322
- // },
323
- // })
324
- // } else {
325
- // // Referencing to a compound or enum.
326
- // const currentId = segToIdentifier(ctx.modSeg)
327
- // const targetId = segToIdentifier(targetSeg)
328
- // if (currentId !== targetId) {
329
- // // The referenced compound/enum is in another module.
330
- // // We should load and check that module first.
331
- // const targetUri = segToUri(targetSeg, ctx)
332
- // const ensured = targetUri ? await ctx.ensureChecked(targetUri) : false
333
- // if (!ensured) {
334
- // ctx.err.report(
335
- // localize('mcdoc.checker.ident-path.unknown-module', localeQuote(targetId)),
336
- // Range.span(token, identPath)
337
- // )
338
- // return undefined
339
- // }
340
- // }
341
- // return ctx.symbols
342
- // .query(ctx.doc, 'mcdoc', targetId, token.value)
343
- // .ifUnknown(() => ctx.err.report(
344
- // localize('mcdoc.checker.ident-path.unknown-identifier', localeQuote(token.value), localeQuote(targetId)),
345
- // Range.span(token, identPath)
346
- // ))
347
- // .elseResolveAlias()
348
- // .elseEnter({
349
- // usage: {
350
- // type: 'reference',
351
- // node: token,
352
- // },
353
- // })
354
- // }
355
- // }
356
- // return undefined
357
- // }
358
- //# sourceMappingURL=entry.js.map
@@ -1,2 +0,0 @@
1
- export * from './entry';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./entry"), exports);
18
- //# sourceMappingURL=index.js.map