Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 21, 2025

We were working around the any by doing things like marshalling from any to bytes then back into specific types.

Rather than doing this, I've instead modified the generator to extend the meta model with more types, including one for the initialization options, and then the types needed for completions data. This simplifies a lot of code, though does mean a few more conversions since we need to serialize things like Path and SymbolId in terms of base-ish types as to not depend on random other packages.

This code can be extended in the future for other "resolve" style requests, like rename, code lens, etc.

Additionally, I was able to eliminate even more any; for example, dynamic registration now uses a union type rather than an any, which is a lot easier to reason about.

There are still more any; the client settings, command arguments, progress params, all still use any. Those might be fixable later but are not very helpful to fix at the moment.

I've also included in this PR a few changes I've wanted to make for a while, e.g. using bitwise ops for the required prop detection.

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 replaces the use of any types in LSP protocol definitions with properly typed structures. It extends the LSP meta model to include custom types for initialization options, completion data, and registration options, eliminating the need for runtime type assertions and JSON marshalling workarounds.

Key changes:

  • Generated custom TypeScript-specific types (InitializationOptions, CompletionItemData, AutoImportData, etc.)
  • Replaced RegisterOptions any with a union type of all possible registration option types
  • Removed experimental fields from ClientCapabilities and ServerCapabilities
  • Updated all code to use strongly-typed structures instead of any with type assertions

Reviewed Changes

Copilot reviewed 117 out of 117 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/lsp/lsproto/_generate/generate.mts Added custom structure definitions and model patching logic to generate TypeScript-specific types
internal/lsp/lsproto/_generate/fetchModel.mts Removed InitializeParams renaming hack (now handled in generator)
internal/lsp/lsproto/lsp_generated.go Generated code with new custom types, RegisterOptions union, and removed experimental fields
internal/lsp/server.go Updated to use typed InitializationOptions and RegisterOptions structures
internal/ls/completions.go Replaced CompletionItemData/AutoImportData with lsproto equivalents, updated type conversions
internal/ls/autoimports*.go Updated ExportInfoMapKey references to use lsproto types
internal/fourslash/tests/gen/*.go Updated test expectations to use typed Data fields
internal/fourslash/fourslash.go Removed type assertions, updated to use typed structures directly
internal/fourslash/_scripts/convertFourslash.mts Updated code generation to use lsproto types

@jakebailey jakebailey changed the title Extend LSP our own types to eliminate any, generate more stuff Extend LSP with our own types, generate more stuff Nov 21, 2025
@jakebailey jakebailey changed the title Extend LSP with our own types, generate more stuff Refine LSP with our own types, generate more stuff Nov 21, 2025
@jakebailey jakebailey added this pull request to the merge queue Nov 21, 2025
Merged via the queue into main with commit 63b00de Nov 21, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/generated-lsp-any branch November 21, 2025 18:48
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