coc-python icon indicating copy to clipboard operation
coc-python copied to clipboard

Pylance support?

Open arusahni opened this issue 5 years ago • 14 comments

Microsoft just announced their new Python LSP that includes their typechecker. Given their plan is to deprecate their existing language server, will coc-python adjust accordingly?

Pylance represents a drastic improvement for the Python experience in Visual Studio Code, to which our team has dedicated months of work. The new, free language server offers increased performance and many more features. Because of that, our team’s focus will shift to Pylance to continue evolving it.

In the short-term, you will still be able to use the Microsoft Python Language Server as your choice of language server when writing Python in Visual Studio Code.

Our long-term plan is to transition our Microsoft Python Language Server users over to Pylance and eventually deprecate and remove the old language server as a supported option.

arusahni avatar Jun 30 '20 23:06 arusahni

From the link, Pylance is based on Pyright, maybe you can try this: https://github.com/fannheyward/coc-pyright

After a quick glance, Pylance = Pyright + onnxruntime based AI + LSP.

fannheyward avatar Jul 01 '20 01:07 fannheyward

But the LICENSE says

a)    General. You may install and use any number of copies of the software only with Microsoft Visual Studio, Visual Studio for Mac, Visual Studio Code, Azure DevOps, Team Foundation Server, and successor Microsoft products and services (collectively, the “Visual Studio Products and Services”) to develop and test your applications.

So it's not legit to use it outside of MS products?

jfcherng avatar Jul 03 '20 14:07 jfcherng

Can we replace https://github.com/Microsoft/python-language-server with https://github.com/Microsoft/pyright?

Congee avatar Jul 07 '20 13:07 Congee

Can we replace https://github.com/Microsoft/python-language-server with https://github.com/Microsoft/pyright?

Pyright is only a type checker, not a fully-featured LSP.

languitar avatar Jul 08 '20 09:07 languitar

Can we replace Microsoft/python-language-server with Microsoft/pyright?

Pyright is only a type checker, not a fully-featured LSP.

No. It has LSP features like jump to definition and code completion. It has generally much better experience than MPLS. Microsoft recommends pylanche which uses pyright under the hood now.

Congee avatar Jul 08 '20 13:07 Congee

so.. how do we do to enable this exactly?

dagadbm avatar Jul 21 '20 09:07 dagadbm

I just tried to get it work, here is my coc-settings:

        "pylance": {
            "enable": true,
            "filetypes": ["python"],
            // absolute path to server.bundle.js
            "module": "~/.vscode/extensions/ms-python.vscode-pylance-2020.7.3/server/server.bundle.js",
            "initializationOptions": {},
            "settings": {
                "python.analysis.typeCheckingMode": "basic",
                "python.analysis.diagnosticMode": "openFilesOnly",
                "python.analysis.stubPath": "./typings",
                "python.analysis.autoSearchPaths": true,
                "python.analysis.extraPaths": [],
                "python.analysis.diagnosticSeverityOverrides": {},
                "python.analysis.useLibraryCodeForTypes": true
            }
        },

The configuration options can be found here.

sainnhe avatar Jul 23 '20 08:07 sainnhe

@sainnhe I'm assuming this is under the languageserver section of coc-settings? If so, having installed the plugin in VS Code, I'm getting the following error with your snippet:

[coc.nvim] Module file "~/.vscode/extensions/ms-python.vscode-pylance-2020.7.3/server/server.bundle.js" not found for LS "pylance"

Any tips on debugging this? I've confirmed the file exists at that path, and have tried both the version of the path in your config, as well as an absolute path'd one.

arusahni avatar Jul 28 '20 12:07 arusahni

Weird ... Shouldn't this all be downloaded from you by COC?

dagadbm avatar Jul 28 '20 12:07 dagadbm

This config also works for me:

        "pylance": {
            "enable": true,
            "filetypes": ["python"],
            "command": "node",
            "args": ["/home/sainnhe/.vscode-oss/extensions/ms-python.vscode-pylance-2020.7.3/server/server.bundle.js", "--stdio"],
            "initializationOptions": {},
            "settings": {
                "python.analysis.typeCheckingMode": "basic",
                "python.analysis.diagnosticMode": "openFilesOnly",
                "python.analysis.stubPath": "./typings",
                "python.analysis.autoSearchPaths": true,
                "python.analysis.extraPaths": [],
                "python.analysis.diagnosticSeverityOverrides": {},
                "python.analysis.useLibraryCodeForTypes": true
            }

You can try this command in your terminal:

$ node ~/.vscode-oss/extensions/ms-python.vscode-pylance-2020.7.3/server/server.bundle.js --stdio
Content-Length: 139

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Pylance language server 2020.7.3 (pyright 5004efe5) starting"}}Content-Length: 179

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server root directory: /home/sainnhe/.vscode-oss/extensions/ms-python.vscode-pylance-2020.7.3/server"}}

sainnhe avatar Jul 28 '20 13:07 sainnhe

Btw, I think the preferred solution should be using pyright.

Pyright is an open source python language server maintained by microsoft python team, they distributed the source code under MIT license.

Pylance adds the IntelliCode component on the basis of pyright. IntelliCode seems to be maintained by another team and is distributed under a very strict license, and this is why the python team said it's hard to make pylance open source.

I'm considering switching back to pyright since it's a FOSS.

sainnhe avatar Jul 28 '20 13:07 sainnhe

Any update? Maybe coc-python and coc-pyright can merge into one repo by discarding MPLS

Congee avatar Oct 01 '20 13:10 Congee

@sainnhe Does your setup still work for you with the October release of PyLance? I used your approach and pylance was working, but my configuration was not being read. I looked at the logs and saw that coc was correctly sending a workspace/didChangeConfiguration with everything under settings, but PyLance didn't seem to register the settings.

I had to place the settings fields under the top level. Then they are sent to Pylance when Pylance requests them via workspace/configuration.

smackesey avatar Oct 21 '20 22:10 smackesey

@smackesey I'm using pyright though, but I noticed that there are 2 new configuration options in the latest release of pylance (python.analysis.autoImportCompletions and python.analysis.completeFunctionParens), see https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

Maybe you can add them in your coc settings and try again.

sainnhe avatar Oct 21 '20 23:10 sainnhe