Skip to content

Add isComplete check to Reflection#2155

Merged
montymxb merged 2 commits into
mainfrom
montymxb/node-is-complete
May 20, 2026
Merged

Add isComplete check to Reflection#2155
montymxb merged 2 commits into
mainfrom
montymxb/node-is-complete

Conversation

@montymxb

Copy link
Copy Markdown
Contributor

Candidate feature for adding an isComplete checker to our reflection setup, so we can do built-in checks for whether nodes are missing non-optional properties. This is in response to a number of cases where nodes deviate from their declared type interfaces in the generated ast.ts, which can lead to some nasty surprises when doing validation checks, generation, etc. Really anything that expects the node to conform to it's type. As far as I'm aware, there's been a lot of manual sanity checking to avoid these kinds of cases when they pop up, so the idea here is to try and make that easier to handle up front.

To support this I added in an optional property to the generated property metadata, so we can recover optionality at runtime without too much effort, but then this requires a regeneration of the ast.ts to get the feature working.

Definitely open for suggestions & feedback on this one, as this is the first approach I've come up with.

@montymxb montymxb requested a review from msujew May 18, 2026 12:24

@msujew msujew left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense 👍

Comment thread packages/langium/src/syntax-tree.ts Outdated
@montymxb montymxb requested a review from msujew May 20, 2026 09:05
Comment on lines +269 to +272
const value = (node as GenericAstNode)[prop.name];
if (value === undefined || value === null) {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: Now that I think about this - Arrays are always initialized as empty arrays, even if no explicit default value is set. But here we only check against undefined and null. This means that an array that is empty, but non-optional will still pass this check. Is this intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case that's intended, but it's a good point. This is just meant to avoid accessing any prop that might otherwise crash. So the empty array case should be okay, so long as some value is present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alright, I see. Makes sense 👍

@msujew msujew left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me 👍

@montymxb montymxb merged commit 85ac1e3 into main May 20, 2026
4 checks passed
@montymxb montymxb deleted the montymxb/node-is-complete branch May 20, 2026 09:46
@msujew msujew added this to the v4.3.0 milestone Jun 15, 2026
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