Validate body

This commit is contained in:
Adria Navarro 2025-02-14 12:22:49 +01:00
parent bc015eba1a
commit f2e8888c94
5 changed files with 16 additions and 1 deletions

View File

@ -296,9 +296,19 @@
return return
} }
const { arguments: expectedArguments = [] } = const { arguments: expectedArguments = [], requiresBlock } =
validations[helperName] validations[helperName]
if (requiresBlock && !isBlockStatement(node)) {
diagnostics.push({
from,
to,
severity: "error",
message: `Helper "${helperName}" requires a body.`,
})
return
}
const providedParams = node.params const providedParams = node.params
if (providedParams.length !== expectedArguments.length) { if (providedParams.length !== expectedArguments.length) {

View File

@ -84,6 +84,7 @@ const helpersToCompletion = (
return { return {
label: helperName, label: helperName,
args: helper.args, args: helper.args,
requiresBlock: helper.requiresBlock,
info: () => buildHelperInfoNode(helper), info: () => buildHelperInfoNode(helper),
type: "helper", type: "helper",
section: helperSection, section: helperSection,

View File

@ -113,6 +113,7 @@
...helperOptions.reduce<CodeValidator>((validations, option) => { ...helperOptions.reduce<CodeValidator>((validations, option) => {
validations[option.label] = { validations[option.label] = {
arguments: option.args, arguments: option.args,
requiresBlock: option.requiresBlock,
} }
return validations return validations
}, {}), }, {}),

View File

@ -7,11 +7,13 @@ export type BindingCompletion = (context: CompletionContext) => {
export interface BindingCompletionOption extends Completion { export interface BindingCompletionOption extends Completion {
args?: any[] args?: any[]
requiresBlock?: boolean
} }
export type CodeValidator = Record< export type CodeValidator = Record<
string, string,
{ {
arguments?: any[] arguments?: any[]
requiresBlock?: boolean
} }
> >

View File

@ -2,4 +2,5 @@ export interface Helper {
example: string example: string
description: string description: string
args: any[] args: any[]
requiresBlock?: boolean
} }