-
Notifications
You must be signed in to change notification settings - Fork 192
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
Support LSP for TypeInferenceProvider
#947
Comments
This seems quite doable (and I'm up for writing PRs to do so), the Pyre Query API is considered legacy code - so replacing that with interfacing with https://github.com/python-lsp/python-lsp-jsonrpc looks like a solid library for interfacing through LSP as used in https://github.com/astral-sh/ruff-lsp/blob/main/tests/client/session.py |
Okay, after looking into this quite a bit ... it unfortunately seems like it's not really possible with the given LSP features supported by mypy & pyre
for pyre it seems reasonable to open an issue and ask for improved LSP support. There are other avenues than LSP one could go for though, a quick look at the json files in |
AFAIK our best bet is to use a hover lsp request at least for pyre, have you tried that? @grievejia we've talked about something like this for a while but never really arrived at a nice interface between pyre and LibCST/Fixit |
Yeah I don't think LSP is a good protocol for exposing typing information. As Zsolt mentioned, the best one could do is to ask for hover results, but hover texts are usually tuned towards human consumption (i.e. potentially including a lot of pretty format artifacts and free-formed texts) rather than machine consumptions. Moreover, what exactly is a good structural format of typing info that gets exposed from type checkers is also a surprisingly non-trivial problem, especially when one takes into account language features like generic classes, overloads, protocols, etc. We do have some long-term plan to tackle that problem from Pyre directly and experiment with various ideas, but at the moment it's unclear what that kind of interface would look like. |
Looks like this gives some type info for some symbols, but I'm getting empty info for most symbols and as grievejia says it's formatted with human consumption in mind and only gives minimal info. e.g.
Hover doesn't look like the way to go, and reading more closely through the spec I'm growing uncertain if any of the other requests are fitting for getting the type info. E.g. textDocument/documentSymbol does include @erictraut does |
Randomly found https://github.com/python/mypy/blob/cfec71798175fcbf030d6d114750d6fac454b3c9/misc/find_type.py which works by copying the current file to a temp file, shoving in a line with a |
Pyright's LSP supports hover text. As was mentioned above, hover text output is meant to be human-readable, so it's not a good format for tooling. It sounds like you're attempting to use the language server interface for a purpose it was not designed, so you will likely be disappointed going down that path. If you want access to the underlying type information produced by a static type analyzer, I think you'd be better off calling the analyzer directly and consuming its output in "native" data structures rather than the text representations used in the LSP. |
Okay, LSP is out of the question then. So if we still want the functionality, the alternatives as far as I can tell are:
|
Having access to type information of a node would be hugely beneficial to refactoring. LibCST offers this to Pyre users via the Pyre Query API, but not to projects using other type checkers and there's unfortunately enough variance where this matters.
The other major type checkers (mypy, pyright) all support LSP, as does Pyre.
The text was updated successfully, but these errors were encountered: