-
Notifications
You must be signed in to change notification settings - Fork 744
Refine LSP with our own types, generate more stuff #2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
anywith 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
anywith 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 |
any, generate more stuff
We were working around the
anyby 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
PathandSymbolIdin 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 anany, 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.