Skip to content

Conversation

@jakebailey
Copy link
Member

This PR makes server-to-client requests typesafe using the same info structs used everywhere else.

As part of this, I figured out that our client requests have not been decoding properly at all; they have just been going through the default Go json decoding. This has not bit us because we either ignore the result, or we wanted []any (for settings), so it just so happened to work. This PR also fixes that problem, so we are now actually decoding the responses.

Copy link
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

This PR introduces type-safe server-to-client requests by leveraging RequestInfo structs with generic type parameters. The key improvement is that client request responses are now properly unmarshaled using type-aware decoding instead of relying on Go's default JSON unmarshaling.

Key Changes:

  • Replaced sendRequest with generic sendClientRequest function that uses RequestInfo[Req, Resp] for type safety
  • Changed ResponseMessage.Result field from any to jsontext.Value to defer deserialization
  • Added unmarshalResult function (and generator code) to properly unmarshal response results based on the request method

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/lsp/server.go Migrated all client request calls from sendRequest to type-safe sendClientRequest, properly typed response handling
internal/lsp/lsproto/lsp.go Added UnmarshalResult, NewRequestMessage, and NewNotificationMessage methods to support type-safe request handling
internal/lsp/lsproto/lsp_generated.go Generated unmarshalResult function with method-specific unmarshaling logic for all LSP request types
internal/lsp/lsproto/jsonrpc.go Changed ResponseMessage.Result to jsontext.Value for deferred deserialization; removed old helper functions
internal/lsp/lsproto/_generate/generate.mts Added generator logic for unmarshalResult function to handle response type unmarshaling
internal/fourslash/fourslash.go Updated test helpers to use new NewRequestMessage and NewNotificationMessage methods from info structs

@jakebailey jakebailey added this pull request to the merge queue Nov 17, 2025
Merged via the queue into main with commit a820457 Nov 17, 2025
28 checks passed
@jakebailey jakebailey deleted the jabaile/typesafe-client-requests branch November 17, 2025 17:22
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.

4 participants