4

I installed NeoVim and dense-analysis/ale plugin with vim-plug.

All of those seems to be installed, as the commands starting with :ALE autocomplete in NeoVim.

Then I tried to install PYLS via

python3 -m pip install --user python-language-server

and enabled it in my init.vim file that you can read here :

# File .config/nvim/init.vim
call plug#begin('~/.config/nvim/plugged')
Plug 'dense-analysis/ale'
let g:ale_linters = {'python': ['pyls']}
let g:ale_fixers = {'python': ['black']}
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_enter = 0
let g:ale_completion_enabled = 1
call plug#end()

" Display
set number " show the line numbers
set cursorline " underline the current line
colorscheme koehler " use my preferred palette

" Syntax highlighting
syntax on

" Set tabs to have 4 spaces
set tabstop=4 " nb of spaces in a tab
set softtabstop=4
set shiftwidth=4 " nb of spaces when using << or >>
set expandtab " use spaces when pressing <tab>

" Input
set mouse=a

" Output
set fileformat=unix
set encoding=utf-8

The problem is : commands like ":ALEGoToDefinition" or ":ALEFindReferences" don't work.

I saw that PYLS need Jedi to provide those, so I installed Jedi too.

python3 -m pip install --user jedi

But there's no change.

Here's my :ALEInfo content :

:ALEInfo...
 Current Filetype: python
Available Linters: ['bandit', 'flake8', 'mypy', 'prospector', 'pycodestyle', 'pydocstyle', 'pyflakes', 'pylama', 'pylint', 'pyls', 'pyre', 'vulture']
 Current Filetype: python
Available Linters: ['bandit', 'flake8', 'mypy', 'prospector', 'pycodestyle', 'pydocstyle', 'pyflakes', 'pylama', 'pylint', 'pyls', 'pyre', 'vulture']
  Enabled Linters: ['pyls']
 Suggested Fixers:
  'add_blank_lines_for_python_control_statements' - Add blank lines before control statements.
  'autopep8' - Fix PEP8 issues with autopep8.
  'black' - Fix PEP8 issues with black.
  'isort' - Sort Python imports with isort.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'reorder-python-imports' - Sort Python imports with reorder-python-imports.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'yapf' - Fix Python files with yapf.
 Linter Variables:
let g:ale_python_auto_pipenv = 0
let g:ale_python_pyls_auto_pipenv = 0
let g:ale_python_pyls_config = {}
let g:ale_python_pyls_executable = 'pyls'
let g:ale_python_pyls_use_global = 0
 Global Variables:
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
let g:ale_command_wrapper = v:null
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = v:null
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {'python': ['black']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_linter_aliases = {}
let g:ale_linters = {'python': ['pyls']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = v:null
let g:ale_list_window_size = v:null
let g:ale_loclist_msg_format = v:null
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = v:null
let g:ale_max_signs = v:null
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:null
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = v:null
let g:ale_sign_error = v:null
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = v:null
let g:ale_statusline_format = v:null
let g:ale_type_map = v:null
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

Press ENTER or type command to continue

Did I forget some steps ? Thanks you

4
  • You should probably install jedi using vim plug
    – eyal karni
    Commented Aug 21, 2019 at 17:56
  • Do you mean the jedi-vim plugin ? I tried, but it's no use. It allows to get autocompletion of Jedi directly in Vim, but I want to get this autocompletion with PYLS using Jedi. And the commands I want (like :ALEGoToDefinition) still don't work. Commented Aug 22, 2019 at 13:48
  • Make sure you can import jedi and that pyls is accessible. And that you don't mix python2 and 3. Other than that, I don't know.
    – eyal karni
    Commented Aug 22, 2019 at 20:49
  • I got Command History: (executable check - success) pyls at the end of my ALEInfo and >>> import jedi in Python3 works. Commented Aug 22, 2019 at 21:23

2 Answers 2

2

OP, are you using a Macbook? Here's what worked for me to get :ALEGoToDefinition working in my Python 3.8 projects using Vim 8.2.330 on both my Macbook and my Linux Mint 19.3 machine:

  1. pipx install 'python-language-server[rope]'
installed package python-language-server 0.36.2, Python 3.10.0
  These apps are now globally available
    - pyls
  1. Now if I open up any Python file in Vim and do :ALEInfo it shows pylsp as an available linter on my Macbook, but it shows up as pyls on my Linux Mint 19.3 machine. Interesting.

  2. Macbook: Update ~/.vimrc to include pylsp as a linter for Python:

let g:ale_linters = {
\   'python': ['flake8', 'mypy', 'pylsp'],
\}
  1. Macbook: It still didn't work because the default executable name of pylsp is incorrect. So I went back into my ~/.vimrc and fixed that variable:
let g:ale_python_pylsp_executable = 'pyls'
  1. Now the Macbook is working! On the Linux machine, the name was correct from the beginning, so all I needed to do was add pyls as a linter and everything worked (no need to override the executable variable):
let g:ale_linters = {
\   'python': ['flake8', 'mypy', 'pyls'],
\}
2

python-language-server requires registration. (See Servers-Python)

Here are two options to do this:

  1. Install vim-lsp
  2. Register the python-language-server in .vimrc
if executable('pyls')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pyls',
        \ 'cmd': {server_info->['pyls']},
        \ 'allowlist': ['python'],
        \ })
endif
1
  • I wanted to try, but as soon as I changed my config file to use pyls, that worked fine. Since I can't reproduce the bug, I can't evaluate your response, sorry. Commented Dec 13, 2019 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.