@spyglassmc/mcfunction 0.2.1 → 0.2.3
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/completer/index.js +8 -7
- package/lib/node/command.js +2 -1
- package/lib/parser/command.js +7 -6
- package/lib/tree/util.js +7 -2
- package/package.json +3 -3
package/lib/completer/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import { CommandNode } from '../node/index.js';
|
|
3
|
-
import { categorizeTreeChildren, CommandTreeRegistry, redirect, resolveParentTreeNode } from '../tree/index.js';
|
|
3
|
+
import { categorizeTreeChildren, CommandTreeRegistry, redirect, resolveParentTreeNode, } from '../tree/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* @param getMockNodes A function that returns a mock AST Node from given {@link ArgumentTreeNode}. These mock nodes
|
|
6
6
|
* will be used for completing the argument.
|
|
@@ -26,9 +26,9 @@ export function command(tree, getMockNodes) {
|
|
|
26
26
|
}
|
|
27
27
|
const lastChildNode = core.AstNode.findLastChild(node, ctx.offset);
|
|
28
28
|
if (!lastChildNode) {
|
|
29
|
-
return Object
|
|
30
|
-
.
|
|
31
|
-
|
|
29
|
+
return Object.keys(tree.children ?? {}).map((v) => core.CompletionItem.create(v, ctx.offset, {
|
|
30
|
+
kind: 14 /* core.CompletionKind.Keyword */,
|
|
31
|
+
}));
|
|
32
32
|
}
|
|
33
33
|
const treePath = lastChildNode.path;
|
|
34
34
|
const { treeNode: parentTreeNode } = resolveParentTreeNode(redirect(tree, treePath), tree);
|
|
@@ -37,9 +37,10 @@ export function command(tree, getMockNodes) {
|
|
|
37
37
|
}
|
|
38
38
|
const { literalTreeNodes, argumentTreeNodes } = categorizeTreeChildren(parentTreeNode.children);
|
|
39
39
|
return [
|
|
40
|
-
...literalTreeNodes.map(([name]) => core.CompletionItem.create(name, ctx.offset, {
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
...literalTreeNodes.map(([name]) => core.CompletionItem.create(name, ctx.offset, {
|
|
41
|
+
kind: 14 /* core.CompletionKind.Keyword */,
|
|
42
|
+
})),
|
|
43
|
+
...argumentTreeNodes.flatMap(([_name, treeNode]) => core.Arrayable.toArray(getMockNodes(treeNode, ctx.offset)).flatMap((n) => core.completer.dispatch(n, ctx))),
|
|
43
44
|
];
|
|
44
45
|
};
|
|
45
46
|
}
|
package/lib/node/command.js
CHANGED
|
@@ -25,7 +25,8 @@ export var CommandChildNode;
|
|
|
25
25
|
export var LiteralCommandChildNode;
|
|
26
26
|
(function (LiteralCommandChildNode) {
|
|
27
27
|
function is(node) {
|
|
28
|
-
return node?.type ===
|
|
28
|
+
return (node?.type ===
|
|
29
|
+
'mcfunction:command_child/literal');
|
|
29
30
|
}
|
|
30
31
|
LiteralCommandChildNode.is = is;
|
|
31
32
|
})(LiteralCommandChildNode || (LiteralCommandChildNode = {}));
|
package/lib/parser/command.js
CHANGED
|
@@ -56,14 +56,15 @@ function dispatch(ans, src, ctx, path, rootTreeNode, parentTreeNode, argument) {
|
|
|
56
56
|
? literal(literalTreeNodes.map(([name, _treeNode]) => name), parent.type === 'root')
|
|
57
57
|
: undefined;
|
|
58
58
|
const parsers = [
|
|
59
|
-
...literalParser ? [literalParser] : [],
|
|
60
|
-
...argumentParsers.map(v => v.parser),
|
|
59
|
+
...(literalParser ? [literalParser] : []),
|
|
60
|
+
...argumentParsers.map((v) => v.parser),
|
|
61
61
|
];
|
|
62
62
|
const out = { index: 0 };
|
|
63
63
|
const parser = parsers.length > 1 ? core.any(parsers, out) : parsers[0];
|
|
64
64
|
const result = parser(src, ctx);
|
|
65
65
|
if (result !== core.Failure) {
|
|
66
|
-
const takenName = argumentParsers[out.index - (literalParser ? 1 : 0)]?.name ??
|
|
66
|
+
const takenName = argumentParsers[out.index - (literalParser ? 1 : 0)]?.name ??
|
|
67
|
+
result.value;
|
|
67
68
|
const childPath = [...path, takenName];
|
|
68
69
|
ans.push({
|
|
69
70
|
type: 'mcfunction:command_child',
|
|
@@ -79,7 +80,8 @@ function dispatch(ans, src, ctx, path, rootTreeNode, parentTreeNode, argument) {
|
|
|
79
80
|
if (ctx.config.env.permissionLevel < requiredPermissionLevel) {
|
|
80
81
|
ctx.err.report(localize('mcfunction.parser.no-permission', requiredPermissionLevel, ctx.config.env.permissionLevel), result);
|
|
81
82
|
}
|
|
82
|
-
if (result.type ===
|
|
83
|
+
if (result.type ===
|
|
84
|
+
'mcfunction:command_child/unknown') {
|
|
83
85
|
// Encountered an unsupported parser. Stop parsing this command.
|
|
84
86
|
return false;
|
|
85
87
|
}
|
|
@@ -134,8 +136,7 @@ function wrapWithBrackets(syntax, executable) {
|
|
|
134
136
|
return executable ? `[${syntax}]` : syntax;
|
|
135
137
|
}
|
|
136
138
|
export function treeNodeChildrenToStringArray(children, executable = false) {
|
|
137
|
-
const entries = Object.entries(children)
|
|
138
|
-
.map(([name, treeNode]) => wrapWithBrackets(treeNodeToString(name, treeNode), executable));
|
|
139
|
+
const entries = Object.entries(children).map(([name, treeNode]) => wrapWithBrackets(treeNodeToString(name, treeNode), executable));
|
|
139
140
|
return entries;
|
|
140
141
|
}
|
|
141
142
|
export function treeNodeChildrenToString(children) {
|
package/lib/tree/util.js
CHANGED
|
@@ -3,9 +3,14 @@ export function redirect(rootTreeNode, path) {
|
|
|
3
3
|
}
|
|
4
4
|
export function resolveParentTreeNode(parentTreeNode, rootTreeNode, parentPath) {
|
|
5
5
|
if (parentTreeNode?.redirect) {
|
|
6
|
-
return {
|
|
6
|
+
return {
|
|
7
|
+
treeNode: redirect(rootTreeNode, parentTreeNode.redirect),
|
|
8
|
+
path: [...parentTreeNode.redirect],
|
|
9
|
+
};
|
|
7
10
|
}
|
|
8
|
-
else if (parentTreeNode &&
|
|
11
|
+
else if (parentTreeNode &&
|
|
12
|
+
!parentTreeNode.children &&
|
|
13
|
+
!parentTreeNode.executable) {
|
|
9
14
|
// The `execute.run` literal tree node doesn't have any property.
|
|
10
15
|
// We should use children from the root tree node in this case.
|
|
11
16
|
return { treeNode: rootTreeNode, path: [] };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcfunction",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.1",
|
|
29
|
+
"@spyglassmc/locales": "0.3.1"
|
|
30
30
|
}
|
|
31
31
|
}
|