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

python-language-server replacement #3722

Closed
arthurio opened this issue May 12, 2021 · 8 comments · Fixed by #3810
Closed

python-language-server replacement #3722

arthurio opened this issue May 12, 2021 · 8 comments · Fixed by #3810
Labels
new tool Support for new linters, fixers, etc.

Comments

@arthurio
Copy link

Name: python-lsp-server
URL: https://github.com/python-lsp/python-lsp-server

It seems that python-language-server is not longer maintained (I asked for confirmation here). I suggest updating the documentation to point to python-lsp-server instead, which is the new actively maintained fork of the project.

In terms of configuration, not much needed to be changed:

Initial config

# .vimrc
let g:ale_linters = {
\   'python': ['flake8', 'pyls', 'bandit', 'mypy'],
\}

let g:ale_python_pyls_config = {
\   'pyls': {
\     'plugins': {
\       'pycodestyle': {
\         'enabled': v:false,
\       },
\       'pyflakes': {
\         'enabled': v:false,
\       },
\       'pydocstyle': {
\         'enabled': v:false,
\       },
\     },
\   },
\}

New config

# .vimrc
let g:ale_linters = {
\   'python': ['flake8', 'pyls', 'bandit', 'mypy'],
\}

let g:ale_python_pyls_executable = "pylsp"

let g:ale_python_pyls_config = {
\   'pylsp': {
\     'plugins': {
\       'pycodestyle': {
\         'enabled': v:false,
\       },
\       'pyflakes': {
\         'enabled': v:false,
\       },
\       'pydocstyle': {
\         'enabled': v:false,
\       },
\     },
\   },
\}

To recap, just set let g:ale_python_pyls_executable to "pylsp" (previously pyls), and update pyls to pylsp in g:ale_python_pyls_config if you need to configure it.

@arthurio arthurio added the new tool Support for new linters, fixers, etc. label May 12, 2021
@jtuz
Copy link

jtuz commented Jun 9, 2021

Thank you @arthurio this was helpful for me

@mkalinski
Copy link

Thanks. Unfortunately, this doesn't seem to work with pylsp installed in a virtualenv. It seems that when setting ale_python_*_executable, ALE expects the executable to be global.

I'm not sure if I'm missing something, or overriding a local executable's name is something ALE just doesn't support.

@arthurio
Copy link
Author

@mkalinski I use virtualenvs and things work fine for me (I use pyenv). I would check the following:

  1. Run which pylsp from the folder you launch vim
  2. Can you run other python executables from vim? (does your vim has python support?)
  3. Run :!which python from within vim

For me:

which pylsp
/Users/arthur/.pyenv/shims/pylsp
# in vim
:!which python

/Users/arthur/.pyenv/shims/python

Press ENTER or type command to continue

I hope this helps.

@mkalinski
Copy link

This isn't really my case. I'm using ALE's functionality to automatically use virtualenvs.

When there's a virtualenv named venv or .venv in the root directory of a python project, ALE will enter it to run any configured linters and fixers from there. It has nothing to do with which virtualenv (if any) vim runs in.

This works for other tools I have installed in the virtualenv, that don't have changed executable names, ex. flake8. And I can run pylsp when I enter the virtualenv manually. But after setting g:ale_python_pyls_executable ALE refuses to use this automatic-enter functionality for pylsp.

@jtuz
Copy link

jtuz commented Jun 13, 2021

@mkalinski, if you are using g:ale_virtualenv_dir_names, according to ALE documentation it only look upwards the virtual directory in your root project for all available tools, but it doesn't load your virtualenv like a pyenv activate venv or source venv/bin/activate , so to take effect the configuration above made by @arthurio , I suggest two options to prove:

  1. set g:ale_python_pyls_executable as an absolute path (this can be annoying if you have many projects, you need to change the path each time you work on your projects)
  2. the simplest way, before you open vim or nvim, load your virtualenv whatever your are using pyenv or venv module from python, this will let your .vimrc clean and compatible among your projects

@GerardoGR
Copy link
Contributor

Thank you @arthurio for the sample configuration. Did you manage to have the autocompletion working?. Mine is not working for some reason :(

GerardoGR added a commit to GerardoGR/ale that referenced this issue Jul 9, 2021
As mentioned in dense-analysis#3722 palantir's python-language-server is no longer maintained.
The alternative is to use the community-driven https://github.com/python-lsp/python-lsp-server.
hsanson pushed a commit that referenced this issue Jul 9, 2021
As mentioned in #3722 palantir's python-language-server is no longer maintained.
The alternative is to use the community-driven https://github.com/python-lsp/python-lsp-server.
@arthurio
Copy link
Author

arthurio commented Jul 9, 2021

@GerardoGR Yes autocompletion is working for me 🤷🏻

@GerardoGR
Copy link
Contributor

To answer my own question and in case someone else experience the same. I had set paste in my vimrc config. According to the docs:

ALE automatic completion will not work when 'paste' is active. Only set
'paste' when you are copy and pasting text into your buffers.
source

When I disabled paste (removing it from my vimrc) the auto-completion worked as expected 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new tool Support for new linters, fixers, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants