From 4243c136db7c46c8c336b10d1adf3127534331b2 Mon Sep 17 00:00:00 2001 From: SPGoding Date: Tue, 14 May 2024 16:30:02 -0500 Subject: [PATCH 01/10] =?UTF-8?q?=F0=9F=94=A8=20Attempt=20to=20fix=20build?= =?UTF-8?q?ing=20issues=20on=20MacOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See #1143 --- packages/playground/esbuild.js | 5 ++++- packages/vscode-extension/esbuild.mjs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/playground/esbuild.js b/packages/playground/esbuild.js index febd9556d..157be7aec 100755 --- a/packages/playground/esbuild.js +++ b/packages/playground/esbuild.js @@ -16,7 +16,10 @@ try { platform: 'node', target: ['firefox89', 'chrome93'], bundle: true, - external: ['electron', 'vscode'], + // fsevents is a MacOS specific native extension used by chokidar for file + // watching and should not be bundled: + // https://github.com/SpyglassMC/Spyglass/issues/1143 + external: ['electron', 'fsevents', 'vscode'], sourcemap: isDev, minify: !isDev, }) diff --git a/packages/vscode-extension/esbuild.mjs b/packages/vscode-extension/esbuild.mjs index eaa573198..8736fc2a8 100755 --- a/packages/vscode-extension/esbuild.mjs +++ b/packages/vscode-extension/esbuild.mjs @@ -17,7 +17,10 @@ try { target: 'node16.13', bundle: true, outdir: './dist', - external: ['electron', 'vscode'], + // fsevents is a MacOS specific native extension used by chokidar for file + // watching and should not be bundled: + // https://github.com/SpyglassMC/Spyglass/issues/1143 + external: ['electron', 'fsevents', 'vscode'], sourcemap: isDev, minify: !isDev, }) From f828e55c4daa539954e880cc6e0a6ec46cad35f0 Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Sat, 18 May 2024 19:17:08 -0700 Subject: [PATCH 02/10] Implement 1.20.5+ item slots Fixes #1159 --- packages/java-edition/src/mcfunction/common/index.ts | 5 ++++- .../java-edition/test/mcfunction/parser/argument.spec.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index a63852daf..c349a0658 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -17,14 +17,17 @@ export const ItemSlotArgumentValues = [ ...[...Array(15).keys()].map((n) => `horse.${n}`), ...[...Array(9).keys()].map((n) => `hotbar.${n}`), ...[...Array(27).keys()].map((n) => `inventory.${n}`), + ...[...Array(4).keys()].map((n) => `player.crafting.${n}`), ...[...Array(8).keys()].map((n) => `villager.${n}`), 'armor.chest', 'armor.feet', 'armor.head', 'armor.legs', - 'horse.armor', + 'armor.body', + 'contents', 'horse.chest', 'horse.saddle', + 'player.cursor', 'weapon', 'weapon.mainhand', 'weapon.offhand', diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index ccd79ae85..a8baee6f6 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -152,7 +152,7 @@ const Suites: Partial< content: ['stick', 'minecraft:stick', '#stick', '#stick{foo:bar}'], }, ], - 'minecraft:item_slot': [{ content: ['container.5', 'weapon'] }], + 'minecraft:item_slot': [{ content: ['container.5', 'weapon', 'armor.body'] }], 'minecraft:item_stack': [ { content: ['stick', 'minecraft:stick', 'stick{foo:bar}'], From 9c553dcd0b97cdac585c56425d4018b24a2f7edd Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Sat, 18 May 2024 19:57:29 -0700 Subject: [PATCH 03/10] Use `ReleaseVersion.cmp` as requested --- package-lock.json | 2 +- .../src/mcfunction/common/index.ts | 49 +++++++++++-------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index 02d002f76..75dbf5b5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10981,7 +10981,7 @@ }, "packages/mcdoc-cli": { "name": "@spyglassmc/mcdoc-cli", - "version": "0.1.3", + "version": "0.1.5", "license": "MIT", "dependencies": { "fs-extra": "^11.1.1", diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index c349a0658..e3052d5d3 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -1,4 +1,5 @@ import * as core from '@spyglassmc/core' +import { ReleaseVersion } from '../../dependency' export const ColorArgumentValues = [...core.Color.ColorNames, 'reset'] @@ -11,27 +12,33 @@ export const GamemodeArgumentValues = [ 'spectator', ] -export const ItemSlotArgumentValues = [ - ...[...Array(54).keys()].map((n) => `container.${n}`), - ...[...Array(27).keys()].map((n) => `enderchest.${n}`), - ...[...Array(15).keys()].map((n) => `horse.${n}`), - ...[...Array(9).keys()].map((n) => `hotbar.${n}`), - ...[...Array(27).keys()].map((n) => `inventory.${n}`), - ...[...Array(4).keys()].map((n) => `player.crafting.${n}`), - ...[...Array(8).keys()].map((n) => `villager.${n}`), - 'armor.chest', - 'armor.feet', - 'armor.head', - 'armor.legs', - 'armor.body', - 'contents', - 'horse.chest', - 'horse.saddle', - 'player.cursor', - 'weapon', - 'weapon.mainhand', - 'weapon.offhand', -] +export function getItemSlotArgumentValues(release: ReleaseVersion) { + const output = [ + ...[...Array(54).keys()].map((n) => `container.${n}`), + ...[...Array(27).keys()].map((n) => `enderchest.${n}`), + ...[...Array(15).keys()].map((n) => `horse.${n}`), + ...[...Array(9).keys()].map((n) => `hotbar.${n}`), + ...[...Array(27).keys()].map((n) => `inventory.${n}`), + ...[...Array(8).keys()].map((n) => `villager.${n}`), + 'armor.chest', + 'armor.feet', + 'armor.head', + 'armor.legs', + 'horse.chest', + 'horse.saddle', + 'weapon', + 'weapon.mainhand', + 'weapon.offhand', + ] + if (ReleaseVersion.cmp(release, '1.20.5') >= 0) { + output.push(...[...Array(4).keys()].map((n) => `player.crafting.${n}`), + 'armor.body', + 'contents', + 'player.cursor') + } + else { output.push('horse.armor') } + return output +} export const OperationArgumentValues = [ '=', From cf5b30efac5cb1bfd6259b780dddf733c24749a1 Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Sun, 19 May 2024 12:49:26 -0700 Subject: [PATCH 04/10] Pass `ctx` to everything --- package-lock.json | 15 ++++++++++++++- package.json | 5 ++++- .../java-edition/src/mcfunction/common/index.ts | 3 ++- .../src/mcfunction/completer/argument.ts | 9 ++++++--- .../src/mcfunction/parser/argument.ts | 5 +++-- .../test/mcfunction/parser/argument.spec.ts | 5 ++++- packages/mcfunction/src/completer/index.ts | 4 ++-- packages/mcfunction/src/parser/argument.ts | 1 + packages/mcfunction/src/parser/command.ts | 2 +- 9 files changed, 37 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 75dbf5b5d..19547a8aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,9 @@ "workspaces": [ "packages/**" ], + "dependencies": { + "main": "^1000.0.1" + }, "devDependencies": { "@types/benchmark": "^2.1.2", "@types/mocha": "^10.0.1", @@ -35,7 +38,7 @@ "source-map-support": "^0.5.21", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", - "typescript": "^5.0.4", + "typescript": "^5.4.5", "webpack": "^5.81.0", "webpack-cli": "^5.0.2", "wireit": "^0.9.5" @@ -7172,6 +7175,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/main": { + "version": "1000.0.1", + "resolved": "https://registry.npmjs.org/main/-/main-1000.0.1.tgz", + "integrity": "sha512-zhB0yIsogMo0xGJEusCzS4I13ejvhEJ1MOWi1OR4n77HyhlqgvNNwhOOt5moSdTYd+Vi8B4wPE/MDmhquNHxrA==" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -16433,6 +16441,11 @@ "integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==", "dev": true }, + "main": { + "version": "1000.0.1", + "resolved": "https://registry.npmjs.org/main/-/main-1000.0.1.tgz", + "integrity": "sha512-zhB0yIsogMo0xGJEusCzS4I13ejvhEJ1MOWi1OR4n77HyhlqgvNNwhOOt5moSdTYd+Vi8B4wPE/MDmhquNHxrA==" + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", diff --git a/package.json b/package.json index def1d473e..05979f183 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "source-map-support": "^0.5.21", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", - "typescript": "^5.0.4", + "typescript": "^5.4.5", "webpack": "^5.81.0", "webpack-cli": "^5.0.2", "wireit": "^0.9.5" @@ -93,5 +93,8 @@ "homepage": "https://spyglassmc.com", "bugs": { "url": "https://github.com/SpyglassMC/Spyglass/issues" + }, + "dependencies": { + "main": "^1000.0.1" } } diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index e3052d5d3..ec33c72ea 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -12,7 +12,8 @@ export const GamemodeArgumentValues = [ 'spectator', ] -export function getItemSlotArgumentValues(release: ReleaseVersion) { +export function getItemSlotArgumentValues(ctx: core.ContextBase) { + const release = ctx.project['loadedVersion'] as ReleaseVersion const output = [ ...[...Array(54).keys()].map((n) => `container.${n}`), ...[...Array(27).keys()].map((n) => `enderchest.${n}`), diff --git a/packages/java-edition/src/mcfunction/completer/argument.ts b/packages/java-edition/src/mcfunction/completer/argument.ts index af92cc3b7..017f7e993 100644 --- a/packages/java-edition/src/mcfunction/completer/argument.ts +++ b/packages/java-edition/src/mcfunction/completer/argument.ts @@ -1,6 +1,7 @@ import type { Arrayable, Completer, + CompleterContext, MetaRegistry, RegistryCategory, WorldgenFileCategory, @@ -10,6 +11,7 @@ import { BooleanNode, BrigadierStringOptions, completer, + ContextBase, CompletionItem, CompletionKind, FloatNode, @@ -32,7 +34,7 @@ import { EntityAnchorArgumentValues, GamemodeArgumentValues, HeightmapValues, - ItemSlotArgumentValues, + getItemSlotArgumentValues, MirrorValues, OperationArgumentValues, RotationValues, @@ -58,8 +60,9 @@ import type { ArgumentTreeNode } from '../tree/index.js' export const getMockNodes: mcf.completer.MockNodesGetter = ( rawTreeNode, - range, + ctx: CompleterContext ): Arrayable => { + const range = ctx.offset const treeNode = rawTreeNode as ArgumentTreeNode switch (treeNode.parser) { @@ -118,7 +121,7 @@ export const getMockNodes: mcf.completer.MockNodesGetter = ( case 'minecraft:item_predicate': return ItemNode.mock(range, true) case 'minecraft:item_slot': - return LiteralNode.mock(range, { pool: ItemSlotArgumentValues }) + return LiteralNode.mock(range, { pool: getItemSlotArgumentValues(ctx) }) case 'minecraft:item_stack': return ItemNode.mock(range, false) case 'minecraft:mob_effect': diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 981f9ddf8..18cc33d08 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -10,7 +10,7 @@ import { EntityAnchorArgumentValues, GamemodeArgumentValues, HeightmapValues, - ItemSlotArgumentValues, + getItemSlotArgumentValues, MirrorValues, OperationArgumentValues, RotationValues, @@ -87,6 +87,7 @@ function shouldValidateLength(ctx: core.ParserContext) { */ export const argument: mcf.ArgumentParserGetter = ( rawTreeNode, + ctx: core.ContextBase ): core.Parser | undefined => { const treeNode = rawTreeNode as ArgumentTreeNode @@ -189,7 +190,7 @@ export const argument: mcf.ArgumentParserGetter = ( case 'minecraft:item_predicate': return wrap(itemPredicate) case 'minecraft:item_slot': - return wrap(core.literal(...ItemSlotArgumentValues)) + return wrap(core.literal(...getItemSlotArgumentValues(ctx))) case 'minecraft:item_stack': return wrap(itemStack) case 'minecraft:message': diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index a8baee6f6..c833e39a9 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -4,6 +4,7 @@ import { snapshotWithUri, testParser, } from '@spyglassmc/core/test-out/utils.js' +import { ContextBase } from '@spyglassmc/core' import { argument } from '@spyglassmc/java-edition/lib/mcfunction/parser/index.js' import type { ArgumentTreeNode } from '@spyglassmc/java-edition/lib/mcfunction/tree/index.js' import * as json from '@spyglassmc/json' @@ -296,6 +297,7 @@ nbt.initialize(project) const { meta } = project describe('mcfunction argument parser', () => { + const ctx = ContextBase.create(project) for (const [parserName, cases] of Object.entries(Suites)) { describe(parserName, () => { for (const { content, properties } of cases) { @@ -308,6 +310,7 @@ describe('mcfunction argument parser', () => { const itTitle = `Parse "${showWhitespaceGlyph(string)}"${ properties ? ` with ${JSON.stringify(properties)}` : '' }` + it(itTitle, () => { snapshotWithUri({ specName: `mcfunction argument ${parserName} ${itTitle}`, @@ -318,7 +321,7 @@ describe('mcfunction argument parser', () => { }.spec.js`, import.meta.url, ), - value: testParser(argument(treeNode)!, string, { + value: testParser(argument(treeNode, ctx)!, string, { project: { meta }, removeTopLevelChildren: RemoveExtraChildren.has( parserName, diff --git a/packages/mcfunction/src/completer/index.ts b/packages/mcfunction/src/completer/index.ts index c5dc0dd8c..96280603d 100644 --- a/packages/mcfunction/src/completer/index.ts +++ b/packages/mcfunction/src/completer/index.ts @@ -13,7 +13,7 @@ import { export type MockNodesGetter = ( treeNode: ArgumentTreeNode, - range: core.RangeLike, + range: core.CompleterContext, ) => core.Arrayable /** @@ -79,7 +79,7 @@ export function command( }) ), ...argumentTreeNodes.flatMap(([_name, treeNode]) => - core.Arrayable.toArray(getMockNodes(treeNode, ctx.offset)).flatMap( + core.Arrayable.toArray(getMockNodes(treeNode, ctx)).flatMap( (n) => core.completer.dispatch(n, ctx), ) ), diff --git a/packages/mcfunction/src/parser/argument.ts b/packages/mcfunction/src/parser/argument.ts index ba51828dd..b8b842d86 100644 --- a/packages/mcfunction/src/parser/argument.ts +++ b/packages/mcfunction/src/parser/argument.ts @@ -10,6 +10,7 @@ import type { ArgumentTreeNode } from '../tree/index.js' */ export type ArgumentParserGetter = ( treeNode: ArgumentTreeNode, + ctx: core.ContextBase, ) => core.Parser | undefined export function argumentTreeNodeToString( diff --git a/packages/mcfunction/src/parser/command.ts b/packages/mcfunction/src/parser/command.ts index a3041c92a..b1d2931dc 100644 --- a/packages/mcfunction/src/parser/command.ts +++ b/packages/mcfunction/src/parser/command.ts @@ -91,7 +91,7 @@ function dispatch( const argumentParsers: { name: string; parser: core.Parser }[] = argumentTreeNodes.map(([name, treeNode]) => ({ name, - parser: argument(treeNode) ?? unknown(treeNode), + parser: argument(treeNode, ctx) ?? unknown(treeNode), })) const literalParser = literalTreeNodes.length ? literal( From 4a63f8ab2903446ee1c5c89fd7b1c7becbc1632f Mon Sep 17 00:00:00 2001 From: Misode Date: Tue, 21 May 2024 02:48:30 +0200 Subject: [PATCH 05/10] Revert package.json changes --- package-lock.json | 17 ++--------------- package.json | 5 +---- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 19547a8aa..02d002f76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,9 +11,6 @@ "workspaces": [ "packages/**" ], - "dependencies": { - "main": "^1000.0.1" - }, "devDependencies": { "@types/benchmark": "^2.1.2", "@types/mocha": "^10.0.1", @@ -38,7 +35,7 @@ "source-map-support": "^0.5.21", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", - "typescript": "^5.4.5", + "typescript": "^5.0.4", "webpack": "^5.81.0", "webpack-cli": "^5.0.2", "wireit": "^0.9.5" @@ -7175,11 +7172,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/main": { - "version": "1000.0.1", - "resolved": "https://registry.npmjs.org/main/-/main-1000.0.1.tgz", - "integrity": "sha512-zhB0yIsogMo0xGJEusCzS4I13ejvhEJ1MOWi1OR4n77HyhlqgvNNwhOOt5moSdTYd+Vi8B4wPE/MDmhquNHxrA==" - }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -10989,7 +10981,7 @@ }, "packages/mcdoc-cli": { "name": "@spyglassmc/mcdoc-cli", - "version": "0.1.5", + "version": "0.1.3", "license": "MIT", "dependencies": { "fs-extra": "^11.1.1", @@ -16441,11 +16433,6 @@ "integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==", "dev": true }, - "main": { - "version": "1000.0.1", - "resolved": "https://registry.npmjs.org/main/-/main-1000.0.1.tgz", - "integrity": "sha512-zhB0yIsogMo0xGJEusCzS4I13ejvhEJ1MOWi1OR4n77HyhlqgvNNwhOOt5moSdTYd+Vi8B4wPE/MDmhquNHxrA==" - }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", diff --git a/package.json b/package.json index 05979f183..def1d473e 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "source-map-support": "^0.5.21", "ts-loader": "^9.4.2", "ts-node": "^10.9.1", - "typescript": "^5.4.5", + "typescript": "^5.0.4", "webpack": "^5.81.0", "webpack-cli": "^5.0.2", "wireit": "^0.9.5" @@ -93,8 +93,5 @@ "homepage": "https://spyglassmc.com", "bugs": { "url": "https://github.com/SpyglassMC/Spyglass/issues" - }, - "dependencies": { - "main": "^1000.0.1" } } From f3b989bb0f9ce183476878a4c03e84f35987466f Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Wed, 22 May 2024 00:23:51 -0700 Subject: [PATCH 06/10] Update packages/java-edition/src/mcfunction/parser/argument.ts Co-authored-by: Misode --- packages/java-edition/src/mcfunction/parser/argument.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 18cc33d08..335317fdd 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -190,7 +190,9 @@ export const argument: mcf.ArgumentParserGetter = ( case 'minecraft:item_predicate': return wrap(itemPredicate) case 'minecraft:item_slot': - return wrap(core.literal(...getItemSlotArgumentValues(ctx))) + return wrap((src, ctx) => { + return core.literal(...getItemSlotArgumentValues(ctx))(src, ctx) + }) case 'minecraft:item_stack': return wrap(itemStack) case 'minecraft:message': From 1fb2bda0ad587a18d21551292463ef40ec87fa00 Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Wed, 22 May 2024 00:27:15 -0700 Subject: [PATCH 07/10] Remove extraneous `ctx` from areas where it is no longer needed --- packages/java-edition/src/mcfunction/parser/argument.ts | 1 - packages/java-edition/test/mcfunction/parser/argument.spec.ts | 2 +- packages/mcfunction/src/parser/argument.ts | 1 - packages/mcfunction/src/parser/command.ts | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 335317fdd..54d6a27ab 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -87,7 +87,6 @@ function shouldValidateLength(ctx: core.ParserContext) { */ export const argument: mcf.ArgumentParserGetter = ( rawTreeNode, - ctx: core.ContextBase ): core.Parser | undefined => { const treeNode = rawTreeNode as ArgumentTreeNode diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index c833e39a9..86e40e825 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -321,7 +321,7 @@ describe('mcfunction argument parser', () => { }.spec.js`, import.meta.url, ), - value: testParser(argument(treeNode, ctx)!, string, { + value: testParser(argument(treeNode)!, string, { project: { meta }, removeTopLevelChildren: RemoveExtraChildren.has( parserName, diff --git a/packages/mcfunction/src/parser/argument.ts b/packages/mcfunction/src/parser/argument.ts index b8b842d86..ba51828dd 100644 --- a/packages/mcfunction/src/parser/argument.ts +++ b/packages/mcfunction/src/parser/argument.ts @@ -10,7 +10,6 @@ import type { ArgumentTreeNode } from '../tree/index.js' */ export type ArgumentParserGetter = ( treeNode: ArgumentTreeNode, - ctx: core.ContextBase, ) => core.Parser | undefined export function argumentTreeNodeToString( diff --git a/packages/mcfunction/src/parser/command.ts b/packages/mcfunction/src/parser/command.ts index b1d2931dc..a3041c92a 100644 --- a/packages/mcfunction/src/parser/command.ts +++ b/packages/mcfunction/src/parser/command.ts @@ -91,7 +91,7 @@ function dispatch( const argumentParsers: { name: string; parser: core.Parser }[] = argumentTreeNodes.map(([name, treeNode]) => ({ name, - parser: argument(treeNode, ctx) ?? unknown(treeNode), + parser: argument(treeNode) ?? unknown(treeNode), })) const literalParser = literalTreeNodes.length ? literal( From 9d778a22be825e1cb0e2145791343fd7deeeac57 Mon Sep 17 00:00:00 2001 From: Nico314159 Date: Wed, 22 May 2024 00:30:43 -0700 Subject: [PATCH 08/10] Fix `else` formatting --- packages/java-edition/src/mcfunction/common/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index ec33c72ea..c701216dd 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -36,8 +36,9 @@ export function getItemSlotArgumentValues(ctx: core.ContextBase) { 'armor.body', 'contents', 'player.cursor') + } else { + output.push('horse.armor') } - else { output.push('horse.armor') } return output } From 3043d1d61f40a2b0b42a494e19690dcf7c00bb87 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 22 May 2024 16:06:00 +0200 Subject: [PATCH 09/10] Format files and remove unused ctx variable/import --- packages/java-edition/src/mcfunction/common/index.ts | 12 +++++++----- .../src/mcfunction/completer/argument.ts | 9 +++++---- .../java-edition/src/mcfunction/parser/argument.ts | 4 ++-- .../test/mcfunction/parser/argument.spec.ts | 7 +++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index c701216dd..8fd5f312a 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -32,11 +32,13 @@ export function getItemSlotArgumentValues(ctx: core.ContextBase) { 'weapon.offhand', ] if (ReleaseVersion.cmp(release, '1.20.5') >= 0) { - output.push(...[...Array(4).keys()].map((n) => `player.crafting.${n}`), - 'armor.body', - 'contents', - 'player.cursor') - } else { + output.push( + ...[...Array(4).keys()].map((n) => `player.crafting.${n}`), + 'armor.body', + 'contents', + 'player.cursor', + ) + } else { output.push('horse.armor') } return output diff --git a/packages/java-edition/src/mcfunction/completer/argument.ts b/packages/java-edition/src/mcfunction/completer/argument.ts index 017f7e993..2e06ec5eb 100644 --- a/packages/java-edition/src/mcfunction/completer/argument.ts +++ b/packages/java-edition/src/mcfunction/completer/argument.ts @@ -11,7 +11,6 @@ import { BooleanNode, BrigadierStringOptions, completer, - ContextBase, CompletionItem, CompletionKind, FloatNode, @@ -33,8 +32,8 @@ import { ColorArgumentValues, EntityAnchorArgumentValues, GamemodeArgumentValues, - HeightmapValues, getItemSlotArgumentValues, + HeightmapValues, MirrorValues, OperationArgumentValues, RotationValues, @@ -60,7 +59,7 @@ import type { ArgumentTreeNode } from '../tree/index.js' export const getMockNodes: mcf.completer.MockNodesGetter = ( rawTreeNode, - ctx: CompleterContext + ctx: CompleterContext, ): Arrayable => { const range = ctx.offset const treeNode = rawTreeNode as ArgumentTreeNode @@ -121,7 +120,9 @@ export const getMockNodes: mcf.completer.MockNodesGetter = ( case 'minecraft:item_predicate': return ItemNode.mock(range, true) case 'minecraft:item_slot': - return LiteralNode.mock(range, { pool: getItemSlotArgumentValues(ctx) }) + return LiteralNode.mock(range, { + pool: getItemSlotArgumentValues(ctx), + }) case 'minecraft:item_stack': return ItemNode.mock(range, false) case 'minecraft:mob_effect': diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 54d6a27ab..411569405 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -9,8 +9,8 @@ import { ColorArgumentValues, EntityAnchorArgumentValues, GamemodeArgumentValues, - HeightmapValues, getItemSlotArgumentValues, + HeightmapValues, MirrorValues, OperationArgumentValues, RotationValues, @@ -190,7 +190,7 @@ export const argument: mcf.ArgumentParserGetter = ( return wrap(itemPredicate) case 'minecraft:item_slot': return wrap((src, ctx) => { - return core.literal(...getItemSlotArgumentValues(ctx))(src, ctx) + return core.literal(...getItemSlotArgumentValues(ctx))(src, ctx) }) case 'minecraft:item_stack': return wrap(itemStack) diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index 86e40e825..1251d2ef8 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -4,7 +4,6 @@ import { snapshotWithUri, testParser, } from '@spyglassmc/core/test-out/utils.js' -import { ContextBase } from '@spyglassmc/core' import { argument } from '@spyglassmc/java-edition/lib/mcfunction/parser/index.js' import type { ArgumentTreeNode } from '@spyglassmc/java-edition/lib/mcfunction/tree/index.js' import * as json from '@spyglassmc/json' @@ -153,7 +152,9 @@ const Suites: Partial< content: ['stick', 'minecraft:stick', '#stick', '#stick{foo:bar}'], }, ], - 'minecraft:item_slot': [{ content: ['container.5', 'weapon', 'armor.body'] }], + 'minecraft:item_slot': [{ + content: ['container.5', 'weapon', 'armor.body'], + }], 'minecraft:item_stack': [ { content: ['stick', 'minecraft:stick', 'stick{foo:bar}'], @@ -297,7 +298,6 @@ nbt.initialize(project) const { meta } = project describe('mcfunction argument parser', () => { - const ctx = ContextBase.create(project) for (const [parserName, cases] of Object.entries(Suites)) { describe(parserName, () => { for (const { content, properties } of cases) { @@ -310,7 +310,6 @@ describe('mcfunction argument parser', () => { const itTitle = `Parse "${showWhitespaceGlyph(string)}"${ properties ? ` with ${JSON.stringify(properties)}` : '' }` - it(itTitle, () => { snapshotWithUri({ specName: `mcfunction argument ${parserName} ${itTitle}`, From c8981602b2232a820097d1df0df220a0de9c0717 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 22 May 2024 16:14:29 +0200 Subject: [PATCH 10/10] Fix import syntax + add loadedVersion ctx to tests --- packages/core/test/utils.ts | 2 +- packages/java-edition/src/mcfunction/common/index.ts | 2 +- packages/java-edition/test/mcfunction/parser/argument.spec.ts | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/core/test/utils.ts b/packages/core/test/utils.ts index d3149cf62..65abc82f5 100644 --- a/packages/core/test/utils.ts +++ b/packages/core/test/utils.ts @@ -58,7 +58,7 @@ export function mockProjectData(data: Partial = {}): ProjectData { return { cacheRoot, config: data.config ?? VanillaConfig, - ctx: data.ctx ?? {}, + ctx: data.ctx ?? { loadedVersion: '1.15' }, downloader, ensureBindingStarted: data.ensureBindingStarted!, externals, diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index 8fd5f312a..ab0df9f87 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -1,5 +1,5 @@ import * as core from '@spyglassmc/core' -import { ReleaseVersion } from '../../dependency' +import { ReleaseVersion } from '../../dependency/index.js' export const ColorArgumentValues = [...core.Color.ColorNames, 'reset'] diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index 1251d2ef8..ccd79ae85 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -152,9 +152,7 @@ const Suites: Partial< content: ['stick', 'minecraft:stick', '#stick', '#stick{foo:bar}'], }, ], - 'minecraft:item_slot': [{ - content: ['container.5', 'weapon', 'armor.body'], - }], + 'minecraft:item_slot': [{ content: ['container.5', 'weapon'] }], 'minecraft:item_stack': [ { content: ['stick', 'minecraft:stick', 'stick{foo:bar}'],