add value completion. - #67
Conversation
b37520c to
3d7462f
Compare
jdesrosiers
left a comment
There was a problem hiding this comment.
I pushed a few minor updates for style and performance. But, more importantly, I added a couple tests to expose some edge cases that were missed.
Overall, I'm not comfortable with how complex this got. I feel like there must be simpler way, but it's ok for now.
ad49419 to
64c03b9
Compare
Thanks for adding those.
i know, it looks pretty overwhelming, i am working on simplifying the logic, i'll update you with the progress very soon. |
| context.negated = keywordId === "https://json-schema.org/keyword/not" ? !negated : negated; | ||
| context.isAnyOf = keywordId === "https://json-schema.org/keyword/anyOf" ? true : (schemaContext.isAnyOf ?? false); | ||
| context.isOneOf = keywordId === "https://json-schema.org/keyword/oneOf" ? true : (schemaContext.isOneOf ?? false); | ||
| context.inIfCondition = keywordId === "https://json-schema.org/keyword/if" ? true : (schemaContext.inIfCondition ?? false); |
There was a problem hiding this comment.
if is a condition, not a constraint, it tests the data, it doesn't restrict it so without this flag we will walk into the if subschema and record its properties as a real constraint on the same property. That constraint then gets intersected with the property's actual schema, which wrongly narrows the completions, hence this flag is necessary.
Description
Suggests values for a property based on what its schema allows.
Completion.tsis now an orchestrator over two providersPropertyCompletionfor keys,ValueCompletionfor values and MatchingSchemaCollector is split intoAnnotationEvaluationPluginandCompletionEvaluationPlugin.What it suggests
Keywords handled
typeenumconstnotallOfanyOfoneOfif/then/else$refpropertiesadditionalPropertiesrequiredThere are two paths, and they exist for different reasons:
resolveValueInfohelper reads a property's own subschema statically, because when we're typing "color": there's no value yet for the validator to go into. That path has to interpret applicator keywords itself, which is why$refandthen/elseappear there explicitly.Out of scope for this PR.
Testing
45 value-completion tests (1 skipped) , all asserting the complete response. Value tests are grouped by keyword with comment markers.