Skip to content
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

Add pyright support #299

Closed
mjlbach opened this issue Jul 6, 2020 · 12 comments · Fixed by #303
Closed

Add pyright support #299

mjlbach opened this issue Jul 6, 2020 · 12 comments · Fixed by #303
Labels
bug Something isn't working

Comments

@mjlbach
Copy link
Contributor

mjlbach commented Jul 6, 2020

Microsoft is moving on to a proprietary language server backend for python in vscode, pylance, which is implemented on top of the pyright library. It seems like development will be ceasing on the C# Microsoft Python Language Server in favor of this implementation (which is JS based, but apparently somehow much faster). Pyright also includes a language server implementation (sans some additional ML powered intellisense features in pyright). Coc has added support via coc-pyright and there has been some discussion on using the pyright in emacs lsp-mode [here] (emacs-lsp/lsp-mode#1863).

I managed to get nvim to launch and connect to the pyright language server as follows:

local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'

local server_name = "pyright"

configs[server_name] = {
  default_config = {
    cmd = {"node", "/home/michael/Repositories/pyright/client/server/server.bundle.js", "--stdio"};
    filetypes = {"python"};
    root_dir = function(fname)
      return util.find_git_ancestor(fname) or vim.loop.os_homedir()
    end;
  };
  docs = {
    description = [[
]];
    default_config = {
      root_dir = [[root_pattern(".git", vim.fn.getcwd())]];
    };
  };
}

-- vim:et ts=2 sw=2

But currently it fails with:

[ DEBUG ] 2020-07-01T22:19:39-0700 ] ...-unwrapped-master/share/nvim/runtime/lua/vim/lsp/rpc.lua:347 ]  "decoded"       {  jsonrpc = "2.0",  method = "window/logMessage",  params = {    message = "Notification handler 'initialized' failed with message: Client doesn't support sending workspace folder change events.",    type = 1  }}
[ DEBUG ] 2020-07-01T22:19:39-0700 ] ...ovim-unwrapped-master/share/nvim/runtime/lua/vim/lsp.lua:343 ]  "notification"  "window/logMessage"     {  message = "Notification handler 'initialized' failed with message: Client doesn't support sending workspace folder change events.",  type = 1}
[ DEBUG ] 2020-07-01T22:19:39-0700 ] ...pped-master/share/nvim/runtime/lua/vim/lsp/callbacks.lua:257 ]  "default_callback"      "window/logMessage"     {  client_id = 1,  params = {    message = "Notification handler 'initialized' failed with message: Client doesn't support sending workspace folder change events.",    type = 1  }}
[ ERROR ] 2020-07-01T22:19:39-0700 ] ...pped-master/share/nvim/runtime/lua/vim/lsp/callbacks.lua:226 ]  "Notification handler 'initialized' failed with message: Client doesn't support sending workspace folder change events."
[ DEBUG ] 2020-07-01T22:21:32-0700 ] ...ovim-unwrapped-master/share/nvim/runtime/lua/vim/lsp.lua:587 ]  "on_lines"      1       4       7       7       8       0       0       0       { "" }
@mjlbach mjlbach added the bug Something isn't working label Jul 6, 2020
@kuator
Copy link

kuator commented Jul 9, 2020

Damn you, Microsoft

@mjlbach
Copy link
Contributor Author

mjlbach commented Jul 10, 2020

As of microsoft/pyright#810 pyright language server can be installed via npm

npm install -g pyright
pyright-langserver

@nymann
Copy link

nymann commented Jul 19, 2020

As of microsoft/pyright#810 pyright language server can be installed via npm

npm install -g 
pyright-langserver

Doesn't seem to be in the npm registry?

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/pyright-langserver - Not found
npm ERR! 404
npm ERR! 404  'pyright-langserver@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

@mjlbach
Copy link
Contributor Author

mjlbach commented Jul 19, 2020

@nymann Was missing the package, pyright-langserver --stdio is the command invoked, the package is pyright

@polarmutex
Copy link

FYI while we wait for the PR
I think you can get around the neovim PR by adding the following to the pyright config

before_init = function(initialize_params, config)
            initialize_params['workspaceFolders'] = {{
                name = 'workspace',
                uri = initialize_params['rootUri']
            }}

this will not add, remove, or list the workspace folders, but those functions I think can be added to your init.vim

@aca
Copy link

aca commented Oct 24, 2020

Pylance support If you need.
https://github.com/aca/pylance.nvim

Damn you, Microsoft

@lithammer
Copy link
Collaborator

lithammer commented Oct 29, 2020

Unfortunately, as of v2020.10.3 running Pylance outside of Visual Studio Code no longer works 😞

$ node ~/.vscode/extensions/ms-python.vscode-pylance-2020.10.3/dist/server.bundle.js --stdio
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 andservices
(collectively, the “Visual Studio Products and Services”) to develop and test
your applications. The software is licensed, not sold. This agreement only
gives you some rights to use the software. Microsoft reserves all other rights.
You may not: work around any technical limitations in the software that only
allow you to use it in certain ways; reverse engineer, decompile or disassemble
the software, or otherwise attempt to derive the source code for the software,
except and to the extent required by third party licensing terms governing use
of certain open source components that may be included in the software; remove,
minimize, block, or modify any notices of Microsoft or its suppliers in the
software; use the software in any way that is against the law or to create or
propagate malware; or share, publish, distribute, or lease the software (except
for any distributable code, subject to the terms above), provide the software
as a stand-alone offering for others to use, or transfer the software or this
agreement to any third party.

@jan-xyz
Copy link
Contributor

jan-xyz commented Nov 4, 2020

Using Pyright directly is also the recommended and supported way and that still works.

@dgvogol
Copy link

dgvogol commented Mar 4, 2021

Unfortunately, as of v2020.10.3 running Pylance outside of Visual Studio Code no longer works 😞

$ node ~/.vscode/extensions/ms-python.vscode-pylance-2020.10.3/dist/server.bundle.js --stdio
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 andservices
(collectively, the “Visual Studio Products and Services”) to develop and test
your applications. The software is licensed, not sold. This agreement only
gives you some rights to use the software. Microsoft reserves all other rights.
You may not: work around any technical limitations in the software that only
allow you to use it in certain ways; reverse engineer, decompile or disassemble
the software, or otherwise attempt to derive the source code for the software,
except and to the extent required by third party licensing terms governing use
of certain open source components that may be included in the software; remove,
minimize, block, or modify any notices of Microsoft or its suppliers in the
software; use the software in any way that is against the law or to create or
propagate malware; or share, publish, distribute, or lease the software (except
for any distributable code, subject to the terms above), provide the software
as a stand-alone offering for others to use, or transfer the software or this
agreement to any third party.

It still works, thanks for @aca 👍

$ ELECTRON_RUN_AS_NODE=1 VSCODE_NLS_CONFIG='{"locale": "en"}' node ~/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.0/dist/server.bundle.js --stdio

But why not just use pyright?

@kuator
Copy link

kuator commented Mar 12, 2021

Unfortunately, as of v2020.10.3 running Pylance outside of Visual Studio Code no longer works disappointed

$ node ~/.vscode/extensions/ms-python.vscode-pylance-2020.10.3/dist/server.bundle.js --stdio
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 andservices
(collectively, the “Visual Studio Products and Services”) to develop and test
your applications. The software is licensed, not sold. This agreement only
gives you some rights to use the software. Microsoft reserves all other rights.
You may not: work around any technical limitations in the software that only
allow you to use it in certain ways; reverse engineer, decompile or disassemble
the software, or otherwise attempt to derive the source code for the software,
except and to the extent required by third party licensing terms governing use
of certain open source components that may be included in the software; remove,
minimize, block, or modify any notices of Microsoft or its suppliers in the
software; use the software in any way that is against the law or to create or
propagate malware; or share, publish, distribute, or lease the software (except
for any distributable code, subject to the terms above), provide the software
as a stand-alone offering for others to use, or transfer the software or this
agreement to any third party.

It still works, thanks for @aca +1

$ ELECTRON_RUN_AS_NODE=1 VSCODE_NLS_CONFIG='{"locale": "en"}' node ~/.vscode-server/extensions/ms-python.vscode-pylance-2021.3.0/dist/server.bundle.js --stdio

But why not just use pyright?

rip https://github.com/aca/pylance.nvim

@mjlbach
Copy link
Contributor Author

mjlbach commented Mar 12, 2021

Hi all, please keep issues on topic

@aca
Copy link

aca commented Mar 14, 2021

Due to license issue, I had to delete my repo. Sorry for pylance.nvim user.

mennohofste referenced this issue in linux-cultist/venv-selector.nvim Dec 11, 2023
Pylance has not been supported since the end of 2020 when Microsoft decided to make Pylance a VSCode only option. A hook for it is hence no longer necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants