Skip to content

Disallow explicit null for optional fields#3313

Merged
jakebailey merged 7 commits intomainfrom
jabaile/fix-lsp-gen
Apr 1, 2026
Merged

Disallow explicit null for optional fields#3313
jakebailey merged 7 commits intomainfrom
jabaile/fix-lsp-gen

Conversation

@jakebailey
Copy link
Copy Markdown
Member

Pointer fields were accidentally not checking for null. This has been a bug for a long time; I only noticed it when reading the diff on #3311.

While here, add some tests, for this but also previous stuff that was fixed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds stricter JSON unmarshaling rules for generated LSP structs so explicitly-provided null is rejected for optional non-nullable fields, and adds comprehensive tests covering (un)marshal behaviors and unions.

Changes:

  • Add typeCanBeNull and generator logic to emit null-rejection checks for fields whose meta-model types don’t permit JSON null
  • Add a broad Go test suite covering nullability rules, required-field validation, unions, discriminator handling, and round-trips

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
internal/lsp/lsproto/lsp_json_test.go New tests validating (un)marshal behavior, especially around nullability and unions
internal/lsp/lsproto/_generate/generate.mts Generator updates to detect null-capable types and reject explicit null where disallowed

@jakebailey jakebailey added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 8f15d7f Apr 1, 2026
21 checks passed
@jakebailey jakebailey deleted the jabaile/fix-lsp-gen branch April 1, 2026 21:05
osiewicz added a commit to zed-industries/zed that referenced this pull request Apr 6, 2026
This fixes a crash with new Preview versions of tsgo after microsoft/typescript-go#3313
osiewicz added a commit to zed-industries/zed that referenced this pull request Apr 6, 2026
This fixes a crash with new Preview versions of tsgo after
microsoft/typescript-go#3313

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A
MasoudAlali pushed a commit to MasoudAlali/zed-ide that referenced this pull request Apr 7, 2026
This fixes a crash with new Preview versions of tsgo after
microsoft/typescript-go#3313

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A
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.

3 participants