Skip to content

Commit

Permalink
🔥 Remove CommandTreeRegistry (SpyglassMC#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
SPGoding authored and TheAfroOfDoom committed May 24, 2024
1 parent db4643d commit 9f81954
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 74 deletions.
17 changes: 7 additions & 10 deletions packages/java-edition/src/mcfunction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as core from '@spyglassmc/core'
import * as core from '@spyglassmc/core'
import * as mcf from '@spyglassmc/mcfunction'
import type { McmetaCommands, ReleaseVersion } from '../dependency/index.js'
import * as checker from './checker/index.js'
Expand All @@ -22,17 +22,14 @@ export const initialize = (
) => {
const { meta } = ctx

const tree = core.merge(commands, getPatch(releaseVersion))

mcf.initialize(ctx)
mcf.CommandTreeRegistry.instance.register(
releaseVersion,
commands,
getPatch(releaseVersion),
)

meta.registerLanguage('mcfunction', {
extensions: ['.mcfunction'],
parser: mcf.entry(releaseVersion, parser.argument, true),
completer: mcf.completer.entry(releaseVersion, completer.getMockNodes),
parser: mcf.entry(tree, parser.argument, true),
completer: mcf.completer.entry(tree, completer.getMockNodes),
triggerCharacters: [
' ',
'[',
Expand All @@ -56,7 +53,7 @@ export const initialize = (
meta.registerParser<mcf.CommandNode>(
'mcfunction:command',
mcf.command(
mcf.CommandTreeRegistry.instance.get(releaseVersion),
tree,
parser.argument,
),
)
Expand All @@ -66,5 +63,5 @@ export const initialize = (
completer.register(meta)

meta.registerInlayHintProvider(inlayHintProvider)
meta.registerSignatureHelpProvider(signatureHelpProvider(releaseVersion))
meta.registerSignatureHelpProvider(signatureHelpProvider(tree))
}
5 changes: 2 additions & 3 deletions packages/java-edition/src/mcfunction/signatureHelpProvider.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as core from '@spyglassmc/core'
import * as mcf from '@spyglassmc/mcfunction'
import type { RootTreeNode } from '../dependency'

/**
* Only command options that can be satisfied by the current command node will be listed in `signatures`.
* Only parameters at and immediately after the `offset` will be listed in `parameters`.
*/
export function signatureHelpProvider(
commandTreeName: string,
rootTreeNode: RootTreeNode,
): core.SignatureHelpProvider<core.FileNode<mcf.McfunctionNode>> {
const rootTreeNode = mcf.CommandTreeRegistry.instance.get(commandTreeName)

return (fileNode, ctx) => {
if (fileNode.children[0]?.type !== 'mcfunction:entry') {
// Not mcfunction.
Expand Down
4 changes: 1 addition & 3 deletions packages/mcfunction/src/completer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CommandNode } from '../node/index.js'
import type { ArgumentTreeNode, RootTreeNode } from '../tree/index.js'
import {
categorizeTreeChildren,
CommandTreeRegistry,
redirect,
resolveParentTreeNode,
} from '../tree/index.js'
Expand All @@ -21,11 +20,10 @@ export type MockNodesGetter = (
* will be used for completing the argument.
*/
export function entry(
commandTreeName: string,
tree: RootTreeNode,
getMockNodes: MockNodesGetter,
): core.Completer<McfunctionNode> {
return (node, ctx) => {
const tree = CommandTreeRegistry.instance.get(commandTreeName)
const childNode = core.AstNode.findChild(node, ctx.offset, true)
if (core.CommentNode.is(childNode) || CommandMacroNode.is(childNode)) {
return []
Expand Down
10 changes: 5 additions & 5 deletions packages/mcfunction/src/parser/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type {
CommandNode,
McfunctionNode,
} from '../node/index.js'
import { CommandTreeRegistry } from '../tree/index.js'
import type { RootTreeNode } from '../tree/index.js'
import type { ArgumentParserGetter } from './argument.js'
import { command } from './command.js'

/**
* @throws When there's no command tree associated with `commandTreeName`.
*/
function mcfunction(
commandTreeName: string,
commandTree: RootTreeNode,
argument: ArgumentParserGetter,
): core.Parser<McfunctionNode> {
return (src, ctx) => {
Expand All @@ -35,7 +35,7 @@ function mcfunction(
}
} else {
result = command(
CommandTreeRegistry.instance.get(commandTreeName),
commandTree,
argument,
)(src, ctx)
}
Expand All @@ -58,11 +58,11 @@ const comment = core.comment({
* Disabled by default.
*/
export const entry = (
commandTreeName: string,
commandTree: RootTreeNode,
argument: ArgumentParserGetter,
supportsBackslashContinuation = false,
) => {
const parser = mcfunction(commandTreeName, argument)
const parser = mcfunction(commandTree, argument)
return supportsBackslashContinuation
? core.concatOnTrailingBackslash(parser)
: parser
Expand Down
1 change: 0 additions & 1 deletion packages/mcfunction/src/tree/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './registry.js'
export * from './type.js'
export * from './util.js'
52 changes: 0 additions & 52 deletions packages/mcfunction/src/tree/registry.ts

This file was deleted.

0 comments on commit 9f81954

Please sign in to comment.