微软宣布推出类型服务器协议(Type Server Protocol,简称 TSP),这是一项基于 JSON-RPC 的扩展协议,旨在增强 Python 代码的类型分析数据交互 1。TSP 复用了语言服务器协议(LSP)的数据结构约定,如 Position 和 Range,其协议方法统一使用 "typeServer/" 前缀 1。该协议支持语义化版本管理,并明确指出在 0.x 阶段,次要版本更新可能包含破坏性变更 1。
为了优化并发读取性能,TSP 引入了可选的多连接模式,通过 capabilities.experimental.typeServerMultiConnection 进行协商,目前支持的额外连接传输类型包括 "ipc" 1。在该模式下,主连接负责处理状态变更流量,而额外连接仅限只读访问;会话期间快照标识符必须保持单调递增,且无效句柄定义为 -1 1。协议核心定义了获取计算类型、声明类型及预期类型的请求与响应规范,具体方法包括 typeServer/getComputedType、typeServer/getDeclaredType 和 typeServer/getExpectedType 1。相关产物涵盖 typeServerProtocol.ts、tsp.json 和 tsp.schema.json 文件,最新内容更新已与 Pylance 2026.4.1 版本保持一致 1。
Microsoft has announced the launch of the Type Server Protocol (TSP), a new JSON-RPC-based extension designed to improve the exchange of type analysis data for Python code 1. Building upon existing standards, TSP reuses data shapes and conventions from the Language Server Protocol (LSP), such as Position and Range structures, while distinguishing its specific methods with the "typeServer/" prefix 1. The protocol’s implementation artifacts include typeServerProtocol.ts, tsp.json, and tsp.schema.json 1.
Key Features and Operational Mechanics
The protocol supports semantic versioning, though it notes that minor versions within the 0.x range may introduce breaking changes 1. To optimize concurrency, TSP offers an optional multi-connection mode negotiated via capabilities.experimental.typeServerMultiConnection 1. In this setup, supported transport kinds like 'ipc' allow for additional read-only connections, while the main connection retains ownership of all state-changing traffic 1. Furthermore, snapshot identifiers must strictly not decrease during a session, and invalid handles are designated as -1 1.
Type Queries and Alignment
Specific request and response specifications define how clients retrieve computed types, declared types, and expected types through methods such as typeServer/getComputedType, typeServer/getDeclaredType, and typeServer/getExpectedType 1. The latest content update for the protocol is aligned with Pylance version 2026.4.1 1.
评论
还没有评论,欢迎留下第一条。