neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

Pylance support? #241

Open arusahni opened 4 years ago

arusahni commented 4 years ago

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.

fannheyward commented 4 years ago

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.

jfcherng commented 4 years ago

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?

Congee commented 4 years ago

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

languitar commented 4 years ago

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.

Congee commented 4 years ago

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.

dagadbm commented 4 years ago

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

sainnhe commented 4 years ago

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.

arusahni commented 4 years ago

@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.

dagadbm commented 4 years ago

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

sainnhe commented 4 years ago

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 commented 4 years ago

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.

Congee commented 4 years ago

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

smackesey commented 4 years ago

@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.

sainnhe commented 4 years ago

@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.