microsoft / microsoft/vscode-json-languageservice

code completion breaks when anyOf defines `required` properties.

Open
#205 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
326
Forks
145
Avg merge
22h 10m
Merged PRs (30d)
9

Description

#204 describes an issue with anyOf (and oneOf) error messaging. However, one way to solve this is to provide a schema-specific error message using the custom JSON property errorMessage as illustrated in this example.

However, the use of the required property (or the dependencies property) on anyOf subschemas will prevent monaco from surfacing it as a valid suggestion. In my example above, p1.shape can be fulfilled by both rectangle and square. However, the only autocomplete option that gets offered is rectangle

Screenshot 2023-09-08 at 12 25 21 PM

The reason this occurs is because the square subschema defines a required field side that is only available within that schema. It essentially ends up making square a hidden option for p1.shape critically breaking the expected completion.

PS: If side were to be removed from the required array in L62 of the example, completions start working as expected.

Screenshot 2023-09-08 at 2 19 18 PM

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the linked Monaco examples and inspecting the completion handling for anyOf subschemas with required or dependencies. Done means autocomplete offers both rectangle and square for p1.shape while preserving the expected behavior when side is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.