Bring back async API, allow API connection to LSP process#2620
Bring back async API, allow API connection to LSP process#2620andrewbranch merged 46 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reintroduces the async JSON-RPC-based API that was prototyped in #711 and adds infrastructure for LSP-based API connections. The implementation refactors the API server stack to support both synchronous (MessagePack) and asynchronous (JSON-RPC) protocols, allowing a single api.Session to work over either STDIO or Unix domain socket/named pipe transports.
Changes:
- Introduces a generic
jsonrpcpackage that extracts common JSON-RPC types fromlsproto, enabling code reuse - Adds
api.Sessionwith protocol abstraction supporting both sync (MessagePack) and async (JSON-RPC) connections - Implements LSP custom command
custom/initializeAPISessionto expose API connections to VS Code extensions - Splits TypeScript API client into sync and async variants with shared base interfaces
Reviewed changes
Copilot reviewed 46 out of 48 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/jsonrpc/ | New package with common JSON-RPC types and base protocol handling |
| internal/lsproto/ | Refactored to use jsonrpc types, reducing code duplication |
| internal/api/session.go | Core API session managing requests, registries, and lifecycle |
| internal/api/conn_*.go | Connection implementations for sync and async request handling |
| internal/api/protocol_*.go | Protocol adapters for MessagePack and JSON-RPC |
| internal/api/transport*.go | Platform-specific transport for pipes/sockets |
| internal/api/callbackfs.go | Virtual filesystem with client-side callbacks |
| internal/lsp/server.go | LSP integration for API session initialization |
| _packages/api/src/async/ | New async TypeScript client using vscode-jsonrpc |
| _packages/api/src/base/ | Shared types and object registry for sync/async clients |
| _packages/api/test/ | Split tests into sync and async variants |
| _extension/ | VS Code command to expose API connection paths |
If we wanted to be very clever, we could do what babel does and use |
|
What? What version of tinybench did it install? 3.1.1 doesn't even have that many lines. How could it have installed anything else? Edit: Jake changed it in main 😄 |
| go 1.25 | ||
|
|
||
| require ( | ||
| github.com/Microsoft/go-winio v0.6.2 |
There was a problem hiding this comment.
After merging, we'll need to update NOTICE (I'll do it, no worries)
api.Session) can be used over either STDIO or UDS / named pipe, and communicate over either JSON-RPC or the custom sync protocol we built on top of MessagePack.The API surface area is still early prototype quality and very incomplete; this PR doesn’t add any methods. But the infrastructure provides the beginnings of a path toward replacing TS Server plugins, and will hopefully make it less cumbersome to maintain both a sync and async version of the API. (It’s still pretty annoying in the TS client code, thanks to async function coloring in JavaScript. Possibly future codegen can help us out a little there.)
Also incidentally fixes #2630, as I needed some additional features out of the extension as I started to play with this, which were difficult to add without fixing the lifetime issues.