summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/python/pyls.vim11
-rw-r--r--doc/ale-python.txt12
-rwxr-xr-xtest/command_callback/python_paths/with_virtualenv/env/Scripts/pyls0
-rwxr-xr-xtest/command_callback/python_paths/with_virtualenv/env/bin/pyls0
-rw-r--r--test/command_callback/test_pyls_command_callback.vader49
5 files changed, 69 insertions, 3 deletions
diff --git a/ale_linters/python/pyls.vim b/ale_linters/python/pyls.vim
index 1b91c2c7..9888853f 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 e34b548f..a78cb5ac 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 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/with_virtualenv/env/Scripts/pyls
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 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/python_paths/with_virtualenv/env/bin/pyls
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 00000000..9f9703d7
--- /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(''))