Skip to content

Tag pointers with the tree they were built on - #443

Merged
holodorum merged 2 commits into
kson-org:mainfrom
holodorum:json-pointer-type
Sep 30, 2026
Merged

holodorum merged 2 commits into
kson-org:mainfrom
holodorum:json-pointer-type

Conversation

@holodorum

Copy link
Copy Markdown
Collaborator

A JsonPointer is bare tokens, but the AST and the value tree number a list differently past an element in error. Pointers built on the AST have twice been resolved through a value tree. A quick fix was introduced in #434, but it would be easy to accidentally re-introduce the bug. This PR fixes it more robustly.

TreePointer<N> carries the walker's node type, so resolving an AST pointer on a value tree is now a compile error. A type parameter rather than two pointer classes lets the one generic navigator tag what it builds and check what it resolves. A pointer written against no tree, such as a $ref fragment, is tagged explicitly where it is resolved.

A JsonPointer is bare tokens, but the AST and the value tree number a
list differently past an element in error.  Pointers built on the AST
have twice been resolved through a value tree; e99887d fixed those
sites by convention only.

TreePointer<N> carries the walker's node type, so resolving an AST
pointer on a value tree is now a compile error.  A type parameter
rather than two pointer classes lets the one generic navigator tag
what it builds and check what it resolves.  A pointer written against
no tree, such as a $ref fragment, is tagged explicitly where it is
resolved.

The past-committed-value check and the filled-property filter were
safe only because the strict ksonValue is null for a broken document.
They now read the AST, so a broken document behaves as a valid one;
two completion tests that encoded the old gap now expect this.

@dmarcotte dmarcotte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @holodorum! Excellent tightening of the code's type requirements here. I've left a few comments which I'd prefer to see address, but I don't think any are blockers, so up to you.

}

@Test
fun testNoValueCompletionsAfterCommittedScalarInBrokenDocument() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does "committed" mean in this context?

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.

'Committed' in this context means that the value is complete and the caret has moved past it, as opposed to still typing inside it.

Rename buildJsonPointerToPosition to buildTreePointerToPosition: it
returns a TreePointer<AstNode> now, so the old name misstated its type.
@holodorum
holodorum merged commit 1430ee5 into kson-org:main Sep 30, 2026
1 check passed
@holodorum
holodorum deleted the json-pointer-type branch September 30, 2026 09:34
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