Microsoft's new Type Server Protocol lets tools query Python type analysis directly
Microsoft Announces Type Server Protocol, Extension of Language Server Protocol
Microsoft has published the Type Server Protocol (TSP), a JSON-RPC protocol that lets clients ask a dedicated type server for Python analysis data: protocol version, snapshots, search paths, import resolution, and computed, declared, or expected types. It borrows LSP data shapes like Position and Range and uses a typeServer/ prefix. An optional multi-connection mode opens extra read-only channels for high-volume queries while the main connection keeps ownership of all state changes.
Multi-connection mode is an optional performance feature. It lets a client open additional local channels to the same type server for read-only TSP requests, while the main connection continues to own the mutable workspace state.
- nikolatt
DetachHead (maintainer of basedpyright) has criticized the TSP before:
- https://docs.basedpyright.com/v1.40.2/type-server/
- https://github.com/microsoft/pylance-release/discussions/718...
Ty (the type checker maintained by astral) however will apparently support the TSP: https://github.com/astral-sh/ruff/discussions/23432
- anonymous908213
This should be called Python Type Server Protocol, no? Seems weird to mine the generic protocol namespace for a protocol that only supports Python. Especially coming from the company behind LSP, which actually is generic.
- tobz1000
As someone with minimal knowledge of LSP specifics, I'm a bit confused about why this exists. Is it the case that LSP alone does not provide adequate functionality for Python type queries?
- pipes
Can someone explain what this is to someone like me that doesn't know python very well, but programs a lot in c#?
- PufPufPuf
I just use the Pyrefly extension in VSCode/Zed, run Pyrefly in the CI, and everything works well. The fragmentation around pyright/pylance/basedpyright/cursor-pyright etc. makes it pretty much unusable, you can't get consistent results across IDEs.
- Tarean
So basically adding machine readable type-at-point queries as an lsp extension so Pylance and Pywright can be separated?
The 'result types'format is super python specific, like not having a for all binder. I don't think this specific schema will be used for any non-python languages.
- 0cf8612b2e1e
It kept with UTF-16. New protocol is a chance to correct that poor decision.
- dev_l1x_be
The primary reason i guess is standardizing the type checking, so you can bring your own (3rd party).