@spyglassmc/mcdoc 0.3.8 → 0.3.10
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.
- package/lib/binder/index.js +108 -192
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -4
- package/lib/node/index.d.ts +5 -0
- package/lib/node/index.js +76 -131
- package/lib/parser/index.js +97 -217
- package/lib/runtime/attribute/builtin.d.ts +3 -0
- package/lib/runtime/attribute/builtin.js +130 -0
- package/lib/runtime/attribute/index.d.ts +22 -0
- package/lib/runtime/attribute/index.js +22 -0
- package/lib/runtime/attribute/validator.d.ts +16 -0
- package/lib/runtime/attribute/validator.js +85 -0
- package/lib/runtime/checker/context.d.ts +34 -0
- package/lib/runtime/checker/context.js +17 -0
- package/lib/runtime/checker/error.d.ts +70 -0
- package/lib/runtime/checker/error.js +352 -0
- package/lib/runtime/checker/index.d.ts +80 -0
- package/lib/runtime/checker/index.js +914 -0
- package/lib/runtime/completer/index.d.ts +20 -0
- package/lib/runtime/completer/index.js +123 -0
- package/lib/runtime/index.d.ts +5 -0
- package/lib/runtime/index.js +5 -0
- package/lib/type/index.d.ts +65 -82
- package/lib/type/index.js +341 -407
- package/lib/uri_processors.js +2 -8
- package/package.json +3 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as core from '@spyglassmc/core';
|
|
2
|
+
import type { McdocType, StructTypePairField } from '../../type/index.js';
|
|
3
|
+
import type { SimplifiedMcdocType } from '../checker/index.js';
|
|
4
|
+
export type SimpleCompletionField = {
|
|
5
|
+
key: string;
|
|
6
|
+
field: core.DeepReadonly<StructTypePairField>;
|
|
7
|
+
};
|
|
8
|
+
export interface McdocCompleterContext extends core.CompleterContext {
|
|
9
|
+
requireCanonical?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function getFields(typeDef: core.DeepReadonly<SimplifiedMcdocType>, ctx: McdocCompleterContext): SimpleCompletionField[];
|
|
12
|
+
export type SimpleCompletionValue = {
|
|
13
|
+
value: string;
|
|
14
|
+
detail?: string;
|
|
15
|
+
kind?: McdocType['kind'];
|
|
16
|
+
completionKind?: core.CompletionKind;
|
|
17
|
+
insertText?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function getValues(typeDef: core.DeepReadonly<McdocType>, ctx: McdocCompleterContext): SimpleCompletionValue[];
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { TypeDefSymbolData } from '../../binder/index.js';
|
|
2
|
+
import { handleAttributes } from '../attribute/index.js';
|
|
3
|
+
export function getFields(typeDef, ctx) {
|
|
4
|
+
switch (typeDef.kind) {
|
|
5
|
+
case 'union':
|
|
6
|
+
const allFields = new Map();
|
|
7
|
+
for (const member of typeDef.members) {
|
|
8
|
+
for (const field of getFields(member, ctx)) {
|
|
9
|
+
allFields.set(field.key, field);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return [...allFields.values()];
|
|
13
|
+
case 'struct':
|
|
14
|
+
return typeDef.fields.flatMap(field => {
|
|
15
|
+
if (typeof field.key === 'string') {
|
|
16
|
+
return [{ key: field.key, field }];
|
|
17
|
+
}
|
|
18
|
+
if (field.key.kind === 'string'
|
|
19
|
+
|| (field.key.kind === 'literal' && field.key.value.kind === 'string')
|
|
20
|
+
|| (field.key.kind === 'enum' && field.key.enumKind === 'string')) {
|
|
21
|
+
const ans = getStringCompletions(field.key, ctx);
|
|
22
|
+
if (ans.length > 0) {
|
|
23
|
+
return ans.map(c => ({ key: c.value, field }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (field.key.kind === 'literal') {
|
|
27
|
+
return [{ key: `${field.key.value.value}`, field }];
|
|
28
|
+
}
|
|
29
|
+
if (field.key.kind === 'string') {
|
|
30
|
+
return getStringCompletions(field.key, ctx)
|
|
31
|
+
.map(c => ({ key: c.value, field }));
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
34
|
+
});
|
|
35
|
+
default:
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// TODO: only accept SimplifiedMcdocType here
|
|
40
|
+
export function getValues(typeDef, ctx) {
|
|
41
|
+
if (typeDef.kind === 'string'
|
|
42
|
+
|| (typeDef.kind === 'literal' && typeDef.value.kind === 'string')
|
|
43
|
+
|| (typeDef.kind === 'enum' && typeDef.enumKind === 'string')) {
|
|
44
|
+
const ans = getStringCompletions(typeDef, ctx);
|
|
45
|
+
if (ans.length > 0) {
|
|
46
|
+
return ans;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
switch (typeDef.kind) {
|
|
50
|
+
case 'union':
|
|
51
|
+
const allValues = new Map();
|
|
52
|
+
for (const member of typeDef.members) {
|
|
53
|
+
for (const value of getValues(member, ctx)) {
|
|
54
|
+
allValues.set(value.value, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [...allValues.values()];
|
|
58
|
+
case 'reference':
|
|
59
|
+
// TODO: de-duplicate this logic from the runtime simplifier
|
|
60
|
+
if (!typeDef.path) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const symbol = ctx.symbols.query(ctx.doc, 'mcdoc', typeDef.path);
|
|
64
|
+
const def = symbol.getData(TypeDefSymbolData.is)?.typeDef;
|
|
65
|
+
if (!def) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
if (typeDef.attributes?.length) {
|
|
69
|
+
return getValues({
|
|
70
|
+
...def,
|
|
71
|
+
attributes: [...typeDef.attributes, ...def.attributes ?? []],
|
|
72
|
+
}, ctx);
|
|
73
|
+
}
|
|
74
|
+
return getValues(def, ctx);
|
|
75
|
+
case 'literal':
|
|
76
|
+
return [{ value: `${typeDef.value.value}`, kind: typeDef.value.kind }];
|
|
77
|
+
case 'boolean':
|
|
78
|
+
return ['false', 'true'].map(v => ({ value: v, kind: 'boolean' }));
|
|
79
|
+
case 'enum':
|
|
80
|
+
// TODO: de-duplicate this logic from the runtime simplifier
|
|
81
|
+
const filteredValues = typeDef.values.filter(value => {
|
|
82
|
+
let keep = true;
|
|
83
|
+
handleAttributes(value.attributes, ctx, (handler, config) => {
|
|
84
|
+
if (!keep || !handler.filterElement) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!handler.filterElement(config, ctx)) {
|
|
88
|
+
keep = false;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return keep;
|
|
92
|
+
});
|
|
93
|
+
return filteredValues.map(v => ({
|
|
94
|
+
value: `${v.value}`,
|
|
95
|
+
detail: v.identifier,
|
|
96
|
+
kind: typeDef.enumKind ?? 'string',
|
|
97
|
+
}));
|
|
98
|
+
default:
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function getStringCompletions(typeDef, ctx) {
|
|
103
|
+
const ans = [];
|
|
104
|
+
handleAttributes(typeDef.attributes, ctx, (handler, config) => {
|
|
105
|
+
const mock = handler.stringMocker?.(config, typeDef, ctx);
|
|
106
|
+
if (!mock) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const items = ctx.meta.getCompleter(mock.type)(mock, ctx);
|
|
110
|
+
ans.push(...items.map(item => ({
|
|
111
|
+
value: item.label,
|
|
112
|
+
kind: 'string',
|
|
113
|
+
detail: item.detail,
|
|
114
|
+
completionKind: item.kind,
|
|
115
|
+
insertText: item.insertText,
|
|
116
|
+
})));
|
|
117
|
+
});
|
|
118
|
+
if (ans.length === 0 && typeDef.kind === 'literal') {
|
|
119
|
+
ans.push({ value: `${typeDef.value.value}`, kind: 'string' });
|
|
120
|
+
}
|
|
121
|
+
return ans;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=index.js.map
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
|
-
import type { FullResourceLocation
|
|
2
|
-
import type { EnumKind
|
|
1
|
+
import type { FullResourceLocation } from '@spyglassmc/core';
|
|
2
|
+
import type { EnumKind } from '../node/index.js';
|
|
3
|
+
import { RangeKind } from '../node/index.js';
|
|
4
|
+
export type Attributes = Attribute[];
|
|
5
|
+
export declare namespace Attributes {
|
|
6
|
+
function equals(a: Attributes | undefined, b: Attributes | undefined): boolean;
|
|
7
|
+
}
|
|
3
8
|
export interface Attribute {
|
|
4
9
|
name: string;
|
|
5
10
|
value?: AttributeValue;
|
|
6
11
|
}
|
|
7
|
-
export
|
|
12
|
+
export declare namespace Attribute {
|
|
13
|
+
function equals(a: Attribute, b: Attribute): boolean;
|
|
14
|
+
}
|
|
15
|
+
export type AttributeValue = McdocType | AttributeTreeValue;
|
|
16
|
+
export interface AttributeTreeValue {
|
|
8
17
|
kind: 'tree';
|
|
9
18
|
values: AttributeTree;
|
|
10
|
-
}
|
|
11
|
-
export
|
|
19
|
+
}
|
|
20
|
+
export interface AttributeTree {
|
|
12
21
|
[key: string | number]: AttributeValue;
|
|
13
|
-
}
|
|
22
|
+
}
|
|
23
|
+
export declare namespace AttributeValue {
|
|
24
|
+
function equals(a: AttributeValue, b: AttributeValue): boolean;
|
|
25
|
+
}
|
|
14
26
|
export type NumericRange = {
|
|
15
27
|
kind: RangeKind;
|
|
16
28
|
min?: number;
|
|
17
29
|
max?: number;
|
|
18
30
|
};
|
|
31
|
+
export declare namespace NumericRange {
|
|
32
|
+
function isInRange(range: NumericRange, val: number): boolean;
|
|
33
|
+
function equals(a: NumericRange, b: NumericRange): boolean;
|
|
34
|
+
function intersect(a: NumericRange, b: NumericRange): NumericRange;
|
|
35
|
+
function toString({ kind, min, max }: NumericRange): string;
|
|
36
|
+
}
|
|
19
37
|
export declare const StaticIndexKeywords: readonly ["fallback", "none", "unknown", "spawnitem", "blockitem"];
|
|
20
38
|
export type StaticIndexKeyword = (typeof StaticIndexKeywords)[number];
|
|
21
39
|
export interface StaticIndex {
|
|
@@ -33,76 +51,80 @@ export type Index = StaticIndex | DynamicIndex;
|
|
|
33
51
|
* Corresponds to the IndexBodyNode
|
|
34
52
|
*/
|
|
35
53
|
export type ParallelIndices = Index[];
|
|
54
|
+
export declare namespace ParallelIndices {
|
|
55
|
+
function equals(a: ParallelIndices, b: ParallelIndices): boolean;
|
|
56
|
+
}
|
|
36
57
|
export interface DispatcherData {
|
|
37
58
|
registry: FullResourceLocation;
|
|
38
59
|
parallelIndices: ParallelIndices;
|
|
39
60
|
}
|
|
40
|
-
export interface DispatcherType extends DispatcherData {
|
|
61
|
+
export interface DispatcherType extends DispatcherData, McdocBaseType {
|
|
41
62
|
kind: 'dispatcher';
|
|
42
63
|
}
|
|
43
|
-
export interface StructType {
|
|
64
|
+
export interface StructType extends McdocBaseType {
|
|
44
65
|
kind: 'struct';
|
|
45
66
|
fields: StructTypeField[];
|
|
46
67
|
}
|
|
47
68
|
export type StructTypeField = StructTypePairField | StructTypeSpreadField;
|
|
48
|
-
export interface StructTypePairField {
|
|
69
|
+
export interface StructTypePairField extends McdocBaseType {
|
|
49
70
|
kind: 'pair';
|
|
50
|
-
attributes?: Attribute[];
|
|
51
71
|
key: string | McdocType;
|
|
52
72
|
type: McdocType;
|
|
53
73
|
optional?: boolean;
|
|
74
|
+
deprecated?: boolean;
|
|
75
|
+
desc?: string;
|
|
54
76
|
}
|
|
55
|
-
export interface StructTypeSpreadField {
|
|
77
|
+
export interface StructTypeSpreadField extends McdocBaseType {
|
|
56
78
|
kind: 'spread';
|
|
57
|
-
attributes?: Attribute[];
|
|
58
79
|
type: McdocType;
|
|
59
80
|
}
|
|
60
|
-
export interface EnumType {
|
|
81
|
+
export interface EnumType extends McdocBaseType {
|
|
61
82
|
kind: 'enum';
|
|
62
83
|
enumKind?: EnumKind;
|
|
63
84
|
values: EnumTypeField[];
|
|
64
85
|
}
|
|
65
|
-
export interface EnumTypeField {
|
|
66
|
-
attributes?: Attribute[];
|
|
86
|
+
export interface EnumTypeField extends McdocBaseType {
|
|
67
87
|
identifier: string;
|
|
68
|
-
value: string | number
|
|
88
|
+
value: string | number;
|
|
69
89
|
}
|
|
70
|
-
export interface ReferenceType {
|
|
90
|
+
export interface ReferenceType extends McdocBaseType {
|
|
71
91
|
kind: 'reference';
|
|
72
92
|
path?: string;
|
|
73
93
|
}
|
|
74
|
-
export interface UnionType<T extends McdocType = McdocType> {
|
|
94
|
+
export interface UnionType<T extends McdocType = McdocType> extends McdocBaseType {
|
|
75
95
|
kind: 'union';
|
|
76
96
|
members: T[];
|
|
77
97
|
}
|
|
78
|
-
export interface
|
|
79
|
-
kind: 'attributed';
|
|
80
|
-
attribute: Attribute;
|
|
81
|
-
child: McdocType;
|
|
82
|
-
}
|
|
83
|
-
export interface IndexedType {
|
|
98
|
+
export interface IndexedType extends McdocBaseType {
|
|
84
99
|
kind: 'indexed';
|
|
85
100
|
parallelIndices: Index[];
|
|
86
101
|
child: McdocType;
|
|
87
102
|
}
|
|
88
|
-
export interface TemplateType {
|
|
103
|
+
export interface TemplateType extends McdocBaseType {
|
|
89
104
|
kind: 'template';
|
|
90
105
|
child: McdocType;
|
|
91
106
|
typeParams: {
|
|
92
107
|
path: string;
|
|
93
108
|
}[];
|
|
94
109
|
}
|
|
95
|
-
export interface ConcreteType {
|
|
110
|
+
export interface ConcreteType extends McdocBaseType {
|
|
96
111
|
kind: 'concrete';
|
|
97
112
|
child: McdocType;
|
|
98
113
|
typeArgs: McdocType[];
|
|
99
114
|
}
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
export interface MappedType extends McdocBaseType {
|
|
116
|
+
kind: 'mapped';
|
|
117
|
+
child: McdocType;
|
|
118
|
+
mapping: {
|
|
119
|
+
[path: string]: McdocType;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export declare const EmptyUnion: UnionType<never>;
|
|
123
|
+
export declare function createEmptyUnion(attributes?: Attributes): UnionType<never>;
|
|
124
|
+
export interface KeywordType extends McdocBaseType {
|
|
103
125
|
kind: 'any' | 'boolean' | 'unsafe';
|
|
104
126
|
}
|
|
105
|
-
export interface StringType {
|
|
127
|
+
export interface StringType extends McdocBaseType {
|
|
106
128
|
kind: 'string';
|
|
107
129
|
lengthRange?: NumericRange;
|
|
108
130
|
}
|
|
@@ -119,11 +141,11 @@ export interface LiteralNumericValue {
|
|
|
119
141
|
kind: NumericTypeKind;
|
|
120
142
|
value: number;
|
|
121
143
|
}
|
|
122
|
-
export interface LiteralType {
|
|
144
|
+
export interface LiteralType extends McdocBaseType {
|
|
123
145
|
kind: 'literal';
|
|
124
146
|
value: LiteralValue;
|
|
125
147
|
}
|
|
126
|
-
export interface NumericType {
|
|
148
|
+
export interface NumericType extends McdocBaseType {
|
|
127
149
|
kind: NumericTypeKind;
|
|
128
150
|
valueRange?: NumericRange;
|
|
129
151
|
}
|
|
@@ -133,7 +155,7 @@ export declare const NumericTypeFloatKinds: readonly ["float", "double"];
|
|
|
133
155
|
export type NumericTypeFloatKind = (typeof NumericTypeFloatKinds)[number];
|
|
134
156
|
export declare const NumericTypeKinds: readonly ["byte", "short", "int", "long", "float", "double"];
|
|
135
157
|
export type NumericTypeKind = (typeof NumericTypeKinds)[number];
|
|
136
|
-
export interface PrimitiveArrayType {
|
|
158
|
+
export interface PrimitiveArrayType extends McdocBaseType {
|
|
137
159
|
kind: 'byte_array' | 'int_array' | 'long_array';
|
|
138
160
|
valueRange?: NumericRange;
|
|
139
161
|
lengthRange?: NumericRange;
|
|
@@ -142,63 +164,24 @@ export declare const PrimitiveArrayValueKinds: readonly ["byte", "int", "long"];
|
|
|
142
164
|
export type PrimitiveArrayValueKind = (typeof PrimitiveArrayValueKinds)[number];
|
|
143
165
|
export declare const PrimitiveArrayKinds: readonly ("byte_array" | "int_array" | "long_array")[];
|
|
144
166
|
export type PrimitiveArrayKind = (typeof PrimitiveArrayKinds)[number];
|
|
145
|
-
export interface ListType {
|
|
167
|
+
export interface ListType extends McdocBaseType {
|
|
146
168
|
kind: 'list';
|
|
147
169
|
item: McdocType;
|
|
148
170
|
lengthRange?: NumericRange;
|
|
149
171
|
}
|
|
150
|
-
export interface TupleType {
|
|
172
|
+
export interface TupleType extends McdocBaseType {
|
|
151
173
|
kind: 'tuple';
|
|
152
174
|
items: McdocType[];
|
|
153
175
|
}
|
|
154
|
-
export
|
|
176
|
+
export interface McdocBaseType {
|
|
177
|
+
attributes?: Attributes;
|
|
178
|
+
}
|
|
179
|
+
export type McdocType = DispatcherType | EnumType | KeywordType | ListType | LiteralType | NumericType | PrimitiveArrayType | ReferenceType | StringType | StructType | TupleType | UnionType | IndexedType | TemplateType | ConcreteType | MappedType;
|
|
155
180
|
export declare namespace McdocType {
|
|
181
|
+
function equals(a: McdocType, b: McdocType): boolean;
|
|
156
182
|
function toString(type: McdocType | undefined): string;
|
|
157
183
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
export type DispatchedType = Exclude<McdocType, DispatcherType | UnionType> | UnionType<DispatchedType>;
|
|
162
|
-
/**
|
|
163
|
-
* A type that doesn't include a reference type.
|
|
164
|
-
*/
|
|
165
|
-
export type DereferencedType = Exclude<McdocType, ReferenceType | UnionType> | UnionType<DereferencedType>;
|
|
166
|
-
/**
|
|
167
|
-
* A type that doesn't include a dispatcher type or a reference type.
|
|
168
|
-
*/
|
|
169
|
-
export type TangibleType = Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<TangibleType>;
|
|
170
|
-
/**
|
|
171
|
-
* A type that is {@link TangibleType} and doesn't have any indices.
|
|
172
|
-
*/
|
|
173
|
-
export type ResolvedType = (Exclude<McdocType, DispatcherType | ReferenceType | UnionType> | UnionType<ResolvedType>) & NoIndices;
|
|
174
|
-
type NoIndices = {
|
|
175
|
-
indices?: undefined;
|
|
176
|
-
};
|
|
177
|
-
export interface FlatStructType {
|
|
178
|
-
kind: 'flat_struct';
|
|
179
|
-
fields: Record<string, McdocType>;
|
|
180
|
-
}
|
|
181
|
-
export declare const flattenUnionType: (union: UnionType) => UnionType;
|
|
182
|
-
export declare const unionTypes: (a: McdocType, b: McdocType) => McdocType;
|
|
183
|
-
export declare const simplifyUnionType: (union: UnionType) => McdocType;
|
|
184
|
-
export declare const simplifyListType: (list: ListType) => ListType;
|
|
185
|
-
export declare const simplifyType: (data: McdocType) => McdocType;
|
|
186
|
-
export declare const checkAssignability: ({ source, target, }: {
|
|
187
|
-
source: McdocType | undefined;
|
|
188
|
-
target: McdocType | undefined;
|
|
189
|
-
}) => {
|
|
190
|
-
isAssignable: boolean;
|
|
191
|
-
errorMessage?: string;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* https://spyglassmc.com/user/mcdoc/#p-RuntimeValue
|
|
195
|
-
*/
|
|
196
|
-
export interface RuntimeValue {
|
|
197
|
-
asString(): string | undefined;
|
|
198
|
-
getKeyOnParent(): RuntimeValue | undefined;
|
|
199
|
-
getParent(): RuntimeValue | undefined;
|
|
200
|
-
getValue(key: string): RuntimeValue | undefined;
|
|
201
|
-
}
|
|
202
|
-
export declare function resolveType(inputType: McdocType, ctx: ProcessorContext, value: RuntimeValue | undefined): ResolvedType;
|
|
203
|
-
export {};
|
|
184
|
+
export interface UseStatementBindingData {
|
|
185
|
+
target: readonly string[];
|
|
186
|
+
}
|
|
204
187
|
//# sourceMappingURL=index.d.ts.map
|