Replies: 5 comments 13 replies
-
Thanks for starting the discussion! We (Pyrefly maintainers) can talk with other typechecker maintainers at PyCon next week. There will be a typing summit - it would be great to get feedback there. @lolpack said that Pylance wont be there, so instead it could be raised at a typing meetup where we could get this in front of all of the typechecker maintainers at the same time. Let us know if there are any updates on your side in the mean time. We are in agreement that this approach seems promising to get other type checkers like Pyrefly out to more customers fast. |
Beta Was this translation helpful? Give feedback.
-
We have a working protocol that we're using in Pylance for semantic tokens (meaning this is used for out of proc calls to Pyright). Please feel free to comment on it: It follows most of the same patterns as the LSP. I expect we'll be adding more methods and types to it in the coming weeks. |
Beta Was this translation helpful? Give feedback.
-
honestly this sounds like a needlessly convoluted solution to a problem that shouldn't even exist in the first place. "we want our language server to be closed-source and not usable outside of vscode, but also we want it to be consistent with other editors and CI environments". it goes against the whole point of language servers, you can't have your cake and eat it too. i hope other type checker maintainers are not on board with this, because as far as i can tell this only benefits microsoft and no one else. they want to reap the benefits of the upcoming open-source language servers like ty and pyrefly while still being able to offer exclusive features once one of them inevitably renders pyright/pylance obsolete, because otherwise the user will have too much freedom to switch between editors. |
Beta Was this translation helpful? Give feedback.
-
@kinto0's had some great review feedback and it's made us rethink how we might do TSP. What if instead of a separate protocol, it was just extra messages in the LSP? Something like so: This would change a couple of things:
This would mean no extra configuration steps for a separate type server. Pyright (and others) would simply do what they do now to find settings, keep track of open documents etc, as the LSP lifecycle messages already handle that. Additionally we can work out how to combine different requests if we don't want wholesale replacement by the underlying Type server or by Pylance. One such example might be completions. Pyright at the moment provides fewer completions than Pylance does. We'd combine the results from the two. How we specify the 'mode' for different features we can work out later. Perhaps the experimentalCapabilities provides a mode for every LS capability. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The goal of language servers and the LSP is to abstract out the language-dependent aspects of the editor experience, so that editors can be language-agnostic in many of their feature implementations. That is a much broader scope than the primary goal of a type checker, which is to verify that operations in a program are performed on compatible data types, reporting and/or preventing runtime errors caused by incompatible operations. This suggests that there may be language-dependent features that belong in a language server but not necessarily in a type checker. This begs the question of whether there could be an API similar to LSP but specifically for the functionality of type checkers, while there are language-specific features that can be implemented in a language server on top of this API that can be shared independent of the type checker used. This would mean type checkers could be maintained separately from language servers, whereas in the current scheme of things, each type checker (and they are proliferating, for Python) ends up implementing its own language server with different capabilities. This discussion is to talk about how that might be done and what this
Type Server Protocol
might look like.Pylance's architecture can be simplified like so:
VS code talks to Pylance to do things like:
Internally Pylance is using Pyright to figure some of these things out. Pylance uses Pyright to:
Pylance adds a number of features on top of this, such as:
- Apply to signature help
- Provide links to documentation
- Add code actions for things like 'auto import'
- Rank suggestions based on context
- Support for intellicode suggestions
- Copilot completion context
- Find associated docstring
- Support for goto def inside of strings
- Filter references by type
- Suggest refactoring options
- Align code with style guides
- Prevent conflicts with existing names
- Display results with context information
This separation might be generalized more like so:
Meaning Pylance (or other Python language servers) could be modified to talk any type checker in order to provide the information it needs.
There are a number of challenges that would have to be solved, such as:
On the other hand, there are clear benefits to be obtained from this, as it free type checker authors from having to build LSP implementations while allowing multiple language servers to bloom that can add many features that type checker authors might like but not be motivated to implement. It also allows the type checker to more easily run out of proc, which can have benefits such as enabling easier support of async LSPs, overcoming memory limitations in extension hosts, etc. Another benefit is that the language servers and type checkers can be implemented in different languages; in some editors the language servers may run in-proc and be bound to the same runtime as the editor.
Beta Was this translation helpful? Give feedback.
All reactions