@spyglassmc/mcdoc 0.3.18 → 0.3.20

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,10 +1,11 @@
1
1
  import type { BinderContext, MetaRegistry } from '@spyglassmc/core';
2
2
  import { AsyncBinder } from '@spyglassmc/core';
3
- import type { AdditionalContext } from '../common.js';
4
3
  import type { ModuleNode } from '../node/index.js';
5
4
  import type { SimplifiedMcdocType } from '../runtime/checker/index.js';
6
5
  import type { McdocType } from '../type/index.js';
7
- interface McdocBinderContext extends BinderContext, AdditionalContext {
6
+ interface McdocBinderContext extends BinderContext {
7
+ moduleIdentifier: string;
8
+ isHoisting?: boolean;
8
9
  }
9
10
  export interface TypeDefSymbolData {
10
11
  typeDef: McdocType;
@@ -33,7 +33,7 @@ export async function module_(node, ctx) {
33
33
  ctx.symbols.query({ doc: ctx.doc, node }, 'mcdoc', ctx.moduleIdentifier).amend({
34
34
  data: { data },
35
35
  });
36
- hoist(node, ctx);
36
+ hoist(node, { ...ctx, isHoisting: true });
37
37
  for (const child of node.children) {
38
38
  switch (child.type) {
39
39
  case 'mcdoc:dispatch_statement':
@@ -559,6 +559,10 @@ function convertTypeArgBlock(node, ctx) {
559
559
  }
560
560
  function convertEnum(node, ctx) {
561
561
  const { block, enumKind, identifier } = EnumNode.destruct(node);
562
+ // Return reference if the enum has been hoisted
563
+ if (identifier && !ctx.isHoisting) {
564
+ return { kind: 'reference', path: `${ctx.moduleIdentifier}::${identifier.value}` };
565
+ }
562
566
  // Shortcut if the typeDef has been added to the enum symbol.
563
567
  const symbol = identifier?.symbol ?? node.symbol;
564
568
  if (symbol && TypeDefSymbolData.is(symbol.data) && symbol.data.typeDef.kind === 'enum') {
@@ -571,9 +575,10 @@ function convertEnumBlock(node, ctx) {
571
575
  return fields.map((n) => convertEnumField(n, ctx));
572
576
  }
573
577
  function convertEnumField(node, ctx) {
574
- const { attributes, identifier, value } = EnumFieldNode.destruct(node);
578
+ const { attributes, docComments, identifier, value } = EnumFieldNode.destruct(node);
575
579
  return {
576
580
  attributes: convertAttributes(attributes, ctx),
581
+ desc: DocCommentsNode.asText(docComments),
577
582
  identifier: identifier.value,
578
583
  value: convertEnumValue(value, ctx),
579
584
  };
@@ -587,6 +592,10 @@ function convertEnumValue(node, ctx) {
587
592
  }
588
593
  function convertStruct(node, ctx) {
589
594
  const { block, identifier } = StructNode.destruct(node);
595
+ // Return reference if the struct has been hoisted
596
+ if (identifier && !ctx.isHoisting) {
597
+ return { kind: 'reference', path: `${ctx.moduleIdentifier}::${identifier.value}` };
598
+ }
590
599
  // Shortcut if the typeDef has been added to the struct symbol.
591
600
  const symbol = identifier?.symbol ?? node.symbol;
592
601
  if (symbol && TypeDefSymbolData.is(symbol.data) && symbol.data.typeDef.kind === 'struct') {
package/lib/common.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export type Segments = readonly string[];
2
2
  export declare function identifierToSeg(identifier: string): Segments;
3
3
  export declare function segToIdentifier(seg: Segments): string;
4
- export interface AdditionalContext {
5
- moduleIdentifier: string;
6
- }
7
4
  //# sourceMappingURL=common.d.ts.map
@@ -310,6 +310,7 @@ export interface EnumFieldNode extends AstNode {
310
310
  export declare namespace EnumFieldNode {
311
311
  function destruct(node: EnumFieldNode): {
312
312
  attributes: AttributeNode[];
313
+ docComments?: DocCommentsNode;
313
314
  identifier: IdentifierNode;
314
315
  value: EnumValueNode;
315
316
  };
package/lib/node/index.js CHANGED
@@ -475,6 +475,7 @@ export var EnumFieldNode;
475
475
  function destruct(node) {
476
476
  return {
477
477
  attributes: node.children.filter(AttributeNode.is),
478
+ docComments: node.children.find(DocCommentsNode.is),
478
479
  identifier: node.children.find(IdentifierNode.is),
479
480
  value: node.children.find(EnumValueNode.is),
480
481
  };
@@ -545,7 +545,7 @@ function simplifyReference(typeDef, context) {
545
545
  context.ctx.logger.warn(`Tried to access unknown reference ${typeDef.path}`);
546
546
  return { typeDef: { kind: 'union', members: [] } };
547
547
  }
548
- if (data.simplifiedTypeDef) {
548
+ if (context.ctx.config.env.enableMcdocCaching && data.simplifiedTypeDef) {
549
549
  return { typeDef: data.simplifiedTypeDef };
550
550
  }
551
551
  const simplifiedResult = simplify(data.typeDef, context);
@@ -555,7 +555,7 @@ function simplifyReference(typeDef, context) {
555
555
  attributes: [...typeDef.attributes, ...simplifiedResult.typeDef.attributes ?? []],
556
556
  };
557
557
  }
558
- if (!simplifiedResult.dynamicData) {
558
+ if (context.ctx.config.env.enableMcdocCaching && !simplifiedResult.dynamicData) {
559
559
  symbol.amend({
560
560
  data: {
561
561
  data: {
@@ -604,7 +604,7 @@ function resolveIndices(parallelIndices, symbolMap, symbolQuery, context) {
604
604
  let dynamicData = false;
605
605
  let values = [];
606
606
  function pushValue(key, data) {
607
- if (data.simplifiedTypeDef) {
607
+ if (context.ctx.config.env.enableMcdocCaching && data.simplifiedTypeDef) {
608
608
  if (data.simplifiedTypeDef.kind === 'union') {
609
609
  values.push(...data.simplifiedTypeDef.members);
610
610
  }
@@ -617,7 +617,7 @@ function resolveIndices(parallelIndices, symbolMap, symbolQuery, context) {
617
617
  if (simplifiedResult.dynamicData) {
618
618
  dynamicData = true;
619
619
  }
620
- else if (symbolQuery) {
620
+ else if (context.ctx.config.env.enableMcdocCaching && symbolQuery) {
621
621
  symbolQuery.member(key, s => s.amend({
622
622
  data: { data: { ...data, simplifiedTypeDef: simplifiedResult.typeDef } },
623
623
  }));
@@ -12,6 +12,7 @@ export declare function getFields(typeDef: core.DeepReadonly<SimplifiedMcdocType
12
12
  export type SimpleCompletionValue = {
13
13
  value: string;
14
14
  detail?: string;
15
+ documentation?: string;
15
16
  labelSuffix?: string;
16
17
  kind?: McdocType['kind'];
17
18
  completionKind?: core.CompletionKind;
@@ -94,6 +94,7 @@ export function getValues(typeDef, ctx) {
94
94
  value: `${v.value}`,
95
95
  detail: v.identifier,
96
96
  kind: typeDef.enumKind ?? 'string',
97
+ documentation: v.desc,
97
98
  }));
98
99
  case 'byte':
99
100
  case 'short':
@@ -86,6 +86,7 @@ export interface EnumType extends McdocBaseType {
86
86
  export interface EnumTypeField extends McdocBaseType {
87
87
  identifier: string;
88
88
  value: string | number;
89
+ desc?: string;
89
90
  }
90
91
  export interface ReferenceType extends McdocBaseType {
91
92
  kind: 'reference';
@@ -181,7 +182,4 @@ export declare namespace McdocType {
181
182
  function equals(a: McdocType, b: McdocType): boolean;
182
183
  function toString(type: McdocType | undefined): string;
183
184
  }
184
- export interface UseStatementBindingData {
185
- target: readonly string[];
186
- }
187
185
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/mcdoc",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/SpyglassMC/Spyglass/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@spyglassmc/core": "0.4.15",
29
- "@spyglassmc/locales": "0.3.9"
28
+ "@spyglassmc/core": "0.4.16",
29
+ "@spyglassmc/locales": "0.3.10"
30
30
  }
31
31
  }