[ES|QL] Validation and autocomplete code improvements #182393
Replies: 7 comments
-
Separate AST traversal from validation codeOur current validation routine is essentially a top-down AST traversal that runs various node-type-specific validation routines. For example, there’s a routine for function arguments, and one for commands, and one for options, etc. walk(ast, (node) => {
if (isCommand(node)) {
/* validate command */
messages.push(...validateCommand(node));
}
if (isFunction(node)) {
/* validate function */
messages.push(...validateFunction(node));
}
...
}
return messages; This might require that the AST have bidirectional references since you might have to “reach up” to the parent of a node to perform a proper validation. But, I think this could be a great separation of concerns (separating tree traversal and checking against definitions). I also have a feeling that it would promote type specificity since the node-type checks will happen at the top level and there will be no casting or checking within the subroutines…. |
Beta Was this translation helpful? Give feedback.
-
Handle literal suggestions uniformly and declarativelyRight now we have two ways to suggest literal values. One is the Does this make sense? I would vote for literal suggestions always to be defined in the definition of a parameter. If they need to be generated based on dynamic context, the logic could be housed in a callback attached to the parameter definition, just like we do with custom validation. At the moment, |
Beta Was this translation helpful? Give feedback.
-
Improve names
|
Beta Was this translation helpful? Give feedback.
-
Revisit expression autocomplete logic |
Beta Was this translation helpful? Give feedback.
-
Evaluate AST structure for ease of traversalDoes it make sense to handle arrays like this? Does it make sense to add bidirectional references between parents and children? Does it make sense to define parent-child relationships as |
Beta Was this translation helpful? Give feedback.
-
Constant-only vs literal typesRight now, we have two ways to say "this parameter shouldn't accept fields." One is via the |
Beta Was this translation helpful? Give feedback.
-
Evaluate handling of array typesThe way validation and the AST handle array types is a blindspot for me (Drew) and makes me nervous. E.g. |
Beta Was this translation helpful? Give feedback.
-
That the validation and autocomplete engines work today is a feat in and of itself. However, there is a lot of room for simplification and understandability improvements.
Beta Was this translation helpful? Give feedback.
All reactions