langserver / langserver.github.io

http://langserver.org
202 stars 182 forks source link

Is Pyright a Python language server? #309

Closed huppyflup closed 11 months ago

huppyflup commented 1 year ago

Pyright is in the list of language servers but the repo says that it's a: "Static Type Checker for Python" (https://github.com/microsoft/pyright). With its command-line tool it doesn't seem to behave like an lsp.

keegancsmith commented 1 year ago

I am not sure. I think its best to follow up with the pyright community. They mention the LSP but maybe our links our now outdated? https://github.com/microsoft/pyright#community

huppyflup commented 1 year ago

The community section from your link says “language service functionality is associated with Pylance”, but it is mentioned as lsp in the docs in https://microsoft.github.io/pyright/#/installation?id=language-server and https://microsoft.github.io/pyright/#/features?id=language-server-support. I don’t know if one of these is a better link because the docs seems to lack how it’s used as an lsp. The only thing I found is https://github.com/microsoft/pyright/discussions/3515

(Interestingly the microsoft list of language servers lists neither pylance nor pyright https://microsoft.github.io/language-server-protocol/implementors/servers/)

andrewcrook commented 1 year ago

@huppyflup

(Interestingly the microsoft list of language servers lists neither pylance

pylance is a LSP that now only works with VSCode and Visual Studio I am not sure there is any point listing it really because its not open to LSP clients in general. Microsoft now refers to it as "fully integrate support”.

I am not sure but I think pyright needs a wrapper to turn it into a LSP. Pyright is actually used as a part of pylance so that’s probably why, because they want you to use their products.

huppyflup commented 1 year ago

If it needs a wrapper should then the wrapper be listed instead?

andrewcrook commented 1 year ago

If it needs a wrapper should then the wrapper be listed instead?

Do you know of a pyright LSP wrapper? I don’t.

I’ve seen wrappers as in plugins using it as a command line tool for editors like a linter or static analyser are often wrapped. But I haven't seen one which makes it an actual LSP server. It might be used as a part of a third party LSP with other tools, again if you can find and it if it exists.

There is a plugin on neovim which fakes it as a LSP called null_ls but it’s not an actual fully compatible LSP, only runs on neovim and the author recently announced that he’s archiving the project. Again, you either need to find one or write one.

I know pyright is used in Microsofts pylance but as I said this LSP isn't open to any other LSP clients apart from Microsofts own which defeats the whole idea of LSPs tbh and I think its a bit off on Microsofts behalf.

also there are other Python LSPs

Pegasust commented 11 months ago

pyright provides pyright the CLI to type-check and report, you could theoretically write extend it as a static type checker by using pyright --json. Another big player for static typing that is officially embraced by Python core is mypy, which is used by python-lsp-server as a type-checking backend.

pyright does ship with the lsp: pyright-langserver, where common invocation for an LSP client is pyright-langserver --stdio, see Neovim's lspconfig

So yes, pyright is a Python LSP that supports static type checking based on couple of PEP in pure TypeScript (so it theoretically does not require the Python interpreter, as long as you have the bundled executable) and resort to typestubs for external library type information before optionally using Python interpreter and toolings to resolve and deduce transitive type context onto our project/package

huppyflup commented 11 months ago

I can agree, that with pyright-langserver it's a language server.