mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-19 18:51:14 +08:00
Close #2281 - Separate cwd commands from commands
Working directories are now set seperately from the commands so they can later be swapped out when running linters over projects is supported, and also better support filename mapping for running linters on other machines in future.
This commit is contained in:
@@ -18,7 +18,7 @@ function! ale_linters#python#mypy#GetExecutable(buffer) abort
|
||||
endfunction
|
||||
|
||||
" The directory to change to before running mypy
|
||||
function! s:GetDir(buffer) abort
|
||||
function! ale_linters#python#mypy#GetCwd(buffer) abort
|
||||
" If we find a directory with "mypy.ini" in it use that,
|
||||
" else try and find the "python project" root, or failing
|
||||
" that, run from the same folder as the current file
|
||||
@@ -36,26 +36,19 @@ function! s:GetDir(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#mypy#GetCommand(buffer) abort
|
||||
let l:dir = s:GetDir(a:buffer)
|
||||
let l:executable = ale_linters#python#mypy#GetExecutable(a:buffer)
|
||||
|
||||
let l:exec_args = l:executable =~? 'pipenv$'
|
||||
\ ? ' run mypy'
|
||||
\ : ''
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'python_mypy_options')
|
||||
|
||||
" We have to always switch to an explicit directory for a command so
|
||||
" we can know with certainty the base path for the 'filename' keys below.
|
||||
return ale#path#CdString(l:dir)
|
||||
\ . ale#Escape(l:executable) . l:exec_args
|
||||
\ . (len(l:options) ? (' ' . l:options) : '')
|
||||
return '%e' . l:exec_args
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'python_mypy_options'))
|
||||
\ . ' --show-column-numbers'
|
||||
\ . ' --shadow-file %s %t %s'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#mypy#Handle(buffer, lines) abort
|
||||
let l:dir = s:GetDir(a:buffer)
|
||||
let l:dir = ale_linters#python#mypy#GetCwd(a:buffer)
|
||||
" Look for lines like the following:
|
||||
"
|
||||
" file.py:4: error: No library stub file for module 'django.db'
|
||||
@@ -97,6 +90,7 @@ endfunction
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'mypy',
|
||||
\ 'executable': function('ale_linters#python#mypy#GetExecutable'),
|
||||
\ 'cwd': function('ale_linters#python#mypy#GetCwd'),
|
||||
\ 'command': function('ale_linters#python#mypy#GetCommand'),
|
||||
\ 'callback': 'ale_linters#python#mypy#Handle',
|
||||
\ 'output_stream': 'both'
|
||||
|
||||
Reference in New Issue
Block a user