Skip to content

Commit

Permalink
Fix: Subcommands not parsing selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
outercloudstudio committed Sep 11, 2022
1 parent 4fbc39a commit 2517473
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/components/Languages/Mcfunction/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class CommandValidator {
passed: boolean
argumentsConsumedCount?: number
warnings: editor.IMarkerData[]
diagnostics: editor.IMarkerData[]
}> {
const { MarkerSeverity } = await useMonaco()

Expand All @@ -43,15 +44,18 @@ export class CommandValidator {
return {
passed: false,
warnings: [],
diagnostics: [],
}

let passedSubcommandDefinition

let warnings: editor.IMarkerData[] = []
let diagnostics: editor.IMarkerData[] = []

// Loop over every subcommand definition to check for a matching one
for (const definition of subcommandDefinitions) {
let definitionWarnings = []
let definitionDiagnostics: editor.IMarkerData[] = []
let definitionWarnings: editor.IMarkerData[] = []

let failed = false

Expand Down Expand Up @@ -84,6 +88,18 @@ export class CommandValidator {
break
}

// Validate selector but don't completely fail if selector fail so rest of command can validate as well
if (targetArgument.type == 'selector') {
const result = await this.parseSelector(argument)

if (result.diagnostic)
definitionDiagnostics.push(result.diagnostic)

definitionWarnings = definitionWarnings.concat(
result.warnings
)
}

if (targetArgument.additionalData) {
// Fail if there are additional values that are not met
if (
Expand Down Expand Up @@ -138,20 +154,23 @@ export class CommandValidator {
) {
passedSubcommandDefinition = definition
warnings = definitionWarnings
diagnostics = definitionDiagnostics
}
}

if (!passedSubcommandDefinition) {
return {
passed: false,
warnings: [],
diagnostics: [],
}
} else {
return {
passed: true,
argumentsConsumedCount:
passedSubcommandDefinition.arguments.length,
warnings,
diagnostics,
}
}
}
Expand Down Expand Up @@ -240,6 +259,9 @@ export class CommandValidator {
diagnostic?: editor.IMarkerData
warnings: editor.IMarkerData[]
}> {
console.log(`Parsing Selector!`)
console.log(selectorToken)

const { MarkerSeverity } = await useMonaco()

let warnings: editor.IMarkerData[] = []
Expand Down Expand Up @@ -517,7 +539,6 @@ export class CommandValidator {
)
argumentType = 'full'

// Fail if type does not match, NOTE: Should check scoredata in future when implemented
if (argumentType != 'full') {
return {
passed: false,
Expand Down Expand Up @@ -791,11 +812,15 @@ export class CommandValidator {
tokens.slice(k, tokens.length)
)

definitionWarnings = definitionWarnings.concat(
result.warnings
definitionDiagnostics = definitionDiagnostics.concat(
result.diagnostics
)

if (result.passed) {
definitionWarnings = definitionWarnings.concat(
result.warnings
)

// Skip over tokens consumed in the subcommand validation
k += result.argumentsConsumedCount!

Expand All @@ -805,10 +830,12 @@ export class CommandValidator {
passed: boolean
argumentsConsumedCount?: number
warnings: editor.IMarkerData[]
diagnostics: editor.IMarkerData[]
} = {
passed: true,
argumentsConsumedCount: 0,
warnings: [],
diagnostics: [],
}

while (nextResult.passed) {
Expand All @@ -817,6 +844,11 @@ export class CommandValidator {
tokens.slice(k + 1, tokens.length)
)

definitionDiagnostics =
definitionDiagnostics.concat(
nextResult.diagnostics
)

if (nextResult.passed) {
definitionWarnings =
definitionWarnings.concat(
Expand Down

0 comments on commit 2517473

Please sign in to comment.