ale icon indicating copy to clipboard operation
ale copied to clipboard

Python code-completion not working

Open komibit opened this issue 3 years ago • 1 comments

Information

VIM version

VIM - Vi IMproved 8.2 (2019 DEC 12, Compiled Jan 16 2022)

Operating System: Arch Linux

Whats wrong: Code-completion isn't working even though I think I have everything setup correctly.

So Basically I have already installed the python language server through: pip install 'python-language-server[all]'

Reproducing the bug

  1. I wrote this in my vimrc:
" Autocompletion settings
let g:ale_completion_enabled = 1
set complete+=kspell
set completeopt=menuone,longest,noselect
let g:ale_completion_enabled = 1

" Ale
let g:ale_linters = {
                        \   'python': ['flake8', 'mypy', 'pylsp'],
                        \}
let g:ale_fixers = {
\       '*': ['remove_trailing_lines', 'trim_whitespace'],
\       'python': ['black', 'isort'],
\}

let g:ale_fix_on_save = 1
  1. Fixing and linting worked flawlessly but no autocompletion.
### :ALEInfo
 Current Filetype: python
Available Linters: ['bandit', 'cspell', 'flake8', 'flakehell', 'jedils', 'mypy', 'prospector', 'pycodest
yle', 'pydocstyle', 'pyflakes', 'pylama', 'pylint', 'pylsp', 'pyre', 'pyright', 'vulture']
  Enabled Linters: ['flake8', 'mypy', 'pylsp']
  Ignored Linters: []
 Suggested Fixers:
  'add_blank_lines_for_python_control_statements' - Add blank lines before control statements.
  'autoflake' - Fix flake issues with autoflake.
  'autoimport' - Fix import issues with autoimport.
  '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_auto_poetry = 0
let g:ale_python_flake8_auto_pipenv = 0
let g:ale_python_flake8_auto_poetry = 0
let g:ale_python_flake8_change_directory = 'project'
let g:ale_python_flake8_executable = 'flake8'
let g:ale_python_flake8_options = ''
let g:ale_python_flake8_use_global = 0
let g:ale_python_mypy_auto_pipenv = 0
let g:ale_python_mypy_auto_poetry = 0
let g:ale_python_mypy_executable = 'mypy'
let g:ale_python_mypy_ignore_invalid_syntax = 0
let g:ale_python_mypy_options = ''
let g:ale_python_mypy_show_notes = 1
let g:ale_python_mypy_use_global = 0
let g:ale_python_pylsp_auto_pipenv = 0
let g:ale_python_pylsp_auto_poetry = 0
let g:ale_python_pylsp_config = {}
let g:ale_python_pylsp_executable = 'pylsp'
let g:ale_python_pylsp_options = ''
let g:ale_python_pylsp_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
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 = 1
let g:ale_fixers = {'*': ['remove_trailing_lines', 'trim_whitespace'], 'python': ['black', 'isort']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'python': ['flake8', 'mypy', 'pylsp']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
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 = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
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:

(executable check - success) flake8
(finished - exit code 0) ['/bin/sh', '-c', 'cd ''/var/tmp'' && ''flake8'' --version']

<<<OUTPUT STARTS>>>
3.8.4 (mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.10.2 on Linux
<<<OUTPUT ENDS>>>

(executable check - failure) mypy
(executable check - failure) pylsp
(finished - exit code 1) ['/bin/sh', '-c', 'cd ''/var/tmp'' && ''flake8'' --format=default --stdin-displ
ay-name ''/var/tmp/pypyXX7wyjdL.py'' - < ''/tmp/vIKH2gq/1/pypyXX7wyjdL.py''']

<<<OUTPUT STARTS>>>
/var/tmp/pypyXX7wyjdL.py:1:1: W391 blank line at end of file
<<<OUTPUT ENDS>>>

komibit avatar Jan 29 '22 16:01 komibit

Seems ALE is unable to find the pylsp executable:

(executable check - failure) pylsp

Make sure it is available in your PATH or if you use pipenv or poetry ensure they can find and execute pypls.

hsanson avatar Feb 04 '22 05:02 hsanson

I'm encountering what seems to be the same bug ; to note, pip install "python-language-server[all]" did not install a pylsp command but a pyls command. Might that be the source of the problem?

Bastes avatar Sep 26 '22 14:09 Bastes

@Bastes there seem to be two python language servers:

  • https://github.com/palantir/python-language-server (pyls)
  • https://github.com/python-lsp/python-lsp-server (pylsp)

Not familiar with either but ALE seems to expect the second one (pylsp).

hsanson avatar Sep 30 '22 00:09 hsanson

Thanks @hsanson I know what I was messing up thanks to you :slightly_smiling_face: I'm using asdf to manage the multiple versions of languages I'm using and I was attempting to use pylsp but it was failing to find the executable, so I had switched to pyls to try.

Turns out I had to re-make asdf's shims so that pylsp's shim was in the $PATH.

Now it works and all :slightly_smiling_face: thank you kindly.

Bastes avatar Oct 24 '22 13:10 Bastes