Skip to content

implement property key completion - #53

Open
srivastava-diya wants to merge 8 commits into
hyperjump-io:mainfrom
srivastava-diya:completion-simple
Open

implement property key completion#53
srivastava-diya wants to merge 8 commits into
hyperjump-io:mainfrom
srivastava-diya:completion-simple

Conversation

@srivastava-diya

Copy link
Copy Markdown
Collaborator

Adds property-key completion, for properties keyword for now.

  • MatchingSchemaCollector collects the properties keyword's value directly during validation through afterKeyword.

  • Completion and Hover now resolve the AST node via findNodeAtPosition and read annotations from it.

  • validateSchema uses jsonc.parse.

  • Tests : no properties, flat properties, nested object properties.

@srivastava-diya
srivastava-diya marked this pull request as draft July 15, 2026 02:39
@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

I had a doubt, for example lets look at this oneOf schema.

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "oneOf": [
      {
        "properties": {
          "foo": { "type": "string" },
          "bar": { "type": "string" }
        }
      },
      {
        "properties": {
          "foo": { "type": "string" },
          "baz": { "type": "string" }
        }
      }
    ]
  }

And a user is typing this instance

{
    "$schema": "${fixtureSchemaUri}",
    ""
}

here two oneOf branches both match simultaneously and there's no discriminant, so the instance is technically invalid as per JSON Schema since it matched more than one, but we still offer the union of both branches properties rather than recognizing this as an issue in order to show something for completion, so i wanted to ask if this is the right thing to do here or some other behaviour is expected?

@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

also i wanted to ask if i am proceeding correctly? and if i am then how should i strengthen anyOf and oneOf completions? like should i think about more edge cases, add more tests or something?

@jdesrosiers

Copy link
Copy Markdown
Collaborator

here two oneOf branches both match simultaneously and there's no discriminant, so the instance is technically invalid as per JSON Schema since it matched more than one, but we still offer the union of both branches properties rather than recognizing this as an issue in order to show something for completion, so i wanted to ask if this is the right thing to do here or some other behaviour is expected?

I think we want it to behave as much like TypeScript as possible. So, if there are no properties yet, it should show all possibilities,

image

If there's a matching discriminator, we can filter

image image

also i wanted to ask if i am proceeding correctly? and if i am then how should i strengthen anyOf and oneOf completions? like should i think about more edge cases, add more tests or something?

Yes. It looks great so far. Keep trying to come up with edge cases that might break. Something to consider is properties with invalid values and how that affects discriminators and filtering. For example,

image

In this case, the "baz" property should be presented correctly despite "bar" having an error.

@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

I think we want it to behave as much like TypeScript as possible. So, if there are no properties yet, it should show all possibilities,

Sure.

In this case, the "baz" property should be presented correctly despite "bar" having an error.

This one is interesting, gonna add a test that covers this behavior.

… from any alternative where that property fails.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only had time to get through the tests, but they look great! I think the only thing left for this issue if figuring out what how not should work.

Comment on lines +892 to +894
expect(completions).toEqual([
{ label: "foo", kind: CompletionItemKind.Property }
]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should include "a" as well, right? "c" is passing in alternative 2, but there is nothing in alternative 1 that matches "c" and fails. So, I would expect both "a" and "foo" to be suggested.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense, I'll add the "a" as well

@srivastava-diya

srivastava-diya commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

I think the only thing left for this issue if figuring out what how not should work.

yeah and in addition to that i also need to implement the auto : insetion after selecting a property which would be fairly simple but i was thinking i should Also implement the : "" insertion for string , : { } for objects etc. which would require us to look at the subschema of the property, so i was thinking if it is the right time to do it? or would the mechanism be simpler if we do this while we're working for Value-completion.

@jdesrosiers

Copy link
Copy Markdown
Collaborator

I'd consider that value completion to me. Let's get this merged first and work on that next.


type SchemaAnnotationContext = ValidationContext & {
pendingAnnotations?: Annotation;
declaredProperties?: string[];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property names a single branch's properties keyword declares, it lives on the branch's schemaContext

type SchemaAnnotationContext = ValidationContext & {
pendingAnnotations?: Annotation;
declaredProperties?: string[];
passedProperties?: Set<string>;

@srivastava-diya srivastava-diya Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passedProperties the names of properties whose values were valid, added there by each property's own check as it finishes.

pendingAnnotations?: Annotation;
declaredProperties?: string[];
passedProperties?: Set<string>;
failedProperties?: Set<string>;

@srivastava-diya srivastava-diya Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failedProperties Same as above, but for evaluations that returned not valid. Also keyword-scoped so properties, additionalProperties, and patternProperties each accumulate their own.

declaredProperties?: string[];
passedProperties?: Set<string>;
failedProperties?: Set<string>;
rejectedProperties?: Set<string>;

@srivastava-diya srivastava-diya Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejectedProperties The branch level union of every failedProperties set added in from properties additionalproperties , patternproperties under that branch

@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

Hey @jdesrosiers following up on not implementation I think for propertycompletion, the only case that actually matters is not containing required, imo that's the one that forbids a key from existing, so it should be excluded from suggestions. A not wrapping something like properties/const/type restricts values so i think we can leave those right?

@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

I think this is ready for a look. Property key completion is working with not case included.

@srivastava-diya
srivastava-diya marked this pull request as ready for review July 26, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants