From 52f3ad7c75273af3b32d1085a248d14ccc1886df Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 21 Nov 2017 23:51:18 +0000 Subject: [PATCH] Escape the pyls executable in the command, and support running virtualenv pyls executables --- ale_linters/python/pyls.vim | 11 ++++- doc/ale-python.txt | 12 ++++- .../with_virtualenv/env/Scripts/pyls | 0 .../python_paths/with_virtualenv/env/bin/pyls | 0 .../test_pyls_command_callback.vader | 49 +++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100755 test/command_callback/python_paths/with_virtualenv/env/Scripts/pyls create mode 100755 test/command_callback/python_paths/with_virtualenv/env/bin/pyls create mode 100644 test/command_callback/test_pyls_command_callback.vader diff --git a/ale_linters/python/pyls.vim b/ale_linters/python/pyls.vim index 1b91c2c..9888853 100644 --- a/ale_linters/python/pyls.vim +++ b/ale_linters/python/pyls.vim @@ -2,9 +2,16 @@ " Description: A language server for Python call ale#Set('python_pyls_executable', 'pyls') +call ale#Set('python_pyls_use_global', 0) function! ale_linters#python#pyls#GetExecutable(buffer) abort - return ale#Var(a:buffer, 'python_pyls_executable') + return ale#python#FindExecutable(a:buffer, 'python_pyls', ['pyls']) +endfunction + +function! ale_linters#python#pyls#GetCommand(buffer) abort + let l:executable = ale_linters#python#pyls#GetExecutable(a:buffer) + + return ale#Escape(l:executable) endfunction function! ale_linters#python#pyls#GetLanguage(buffer) abort @@ -15,7 +22,7 @@ call ale#linter#Define('python', { \ 'name': 'pyls', \ 'lsp': 'stdio', \ 'executable_callback': 'ale_linters#python#pyls#GetExecutable', -\ 'command_callback': 'ale_linters#python#pyls#GetExecutable', +\ 'command_callback': 'ale_linters#python#pyls#GetCommand', \ 'language_callback': 'ale_linters#python#pyls#GetLanguage', \ 'project_root_callback': 'ale#python#FindProjectRoot', \}) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index e34b548..a78cb5a 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -189,16 +189,26 @@ g:ale_python_pylint_use_global *g:ale_python_pylint_use_global* See |ale-integrations-local-executables| + =============================================================================== pyls *ale-python-pyls* g:ale_python_pyls_executable *g:ale_python_pyls_executable* *b:ale_python_pyls_executable* Type: |String| - Default: `pyls` + Default: `'pyls'` See |ale-integrations-local-executables| + +g:ale_python_pyls_use_global *g:ale_python_pyls_use_global* + *b:ale_python_pyls_use_global* + Type: |Number| + Default: `0` + + See |ale-integrations-local-executables| + + =============================================================================== yapf *ale-python-yapf* diff --git a/test/command_callback/python_paths/with_virtualenv/env/Scripts/pyls b/test/command_callback/python_paths/with_virtualenv/env/Scripts/pyls new file mode 100755 index 0000000..e69de29 diff --git a/test/command_callback/python_paths/with_virtualenv/env/bin/pyls b/test/command_callback/python_paths/with_virtualenv/env/bin/pyls new file mode 100755 index 0000000..e69de29 diff --git a/test/command_callback/test_pyls_command_callback.vader b/test/command_callback/test_pyls_command_callback.vader new file mode 100644 index 0000000..9f9703d --- /dev/null +++ b/test/command_callback/test_pyls_command_callback.vader @@ -0,0 +1,49 @@ +Before: + Save g:ale_python_pyls_executable + Save g:ale_python_pyls_use_global + + unlet! g:ale_python_pyls_executable + unlet! g:ale_python_pyls_use_global + + let b:bin_dir = has('win32') ? 'Scripts' : 'bin' + + call ale#test#SetDirectory('/testplugin/test/command_callback') + + runtime ale_linters/python/pyls.vim + +After: + Restore + + unlet! b:bin_dir + unlet! b:executable + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The pyls command callback should return default string): + AssertEqual ale#Escape('pyls'), + \ ale_linters#python#pyls#GetCommand(bufnr('')) + +Execute(The pyls executable should be configurable): + let g:ale_python_pyls_executable = '~/.local/bin/pyls' + + AssertEqual ale#Escape('~/.local/bin/pyls'), + \ ale_linters#python#pyls#GetCommand(bufnr('')) + +Execute(The pyls executable should be run from the virtualenv path): + call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py') + + let b:executable = ale#path#Winify( + \ g:dir . '/python_paths/with_virtualenv/env/' . b:bin_dir . '/pyls' + \) + + AssertEqual ale#Escape(b:executable), + \ ale_linters#python#pyls#GetCommand(bufnr('')) + +Execute(You should be able to override the pyls virtualenv lookup): + call ale#test#SetFilename('python_paths/with_virtualenv/subdir/foo/bar.py') + + let g:ale_python_pyls_use_global = 1 + + AssertEqual ale#Escape('pyls'), + \ ale_linters#python#pyls#GetCommand(bufnr(''))