@spyglassmc/mcdoc 0.2.0 → 0.3.0

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