diff options
author | w0rp <devw0rp@gmail.com> | 2017-08-20 17:43:42 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-08-20 17:43:42 +0100 |
commit | cc02eb8a5a0e40e23ae5e3cc2a4e92f0353d30b5 (patch) | |
tree | 6324ddde9cd15ed68033a712a0608e11c70f63fc /ale_linters/python | |
parent | 456378cb53dbf38ff0077b8f41894bbdc7c9671e (diff) | |
download | ale-cc02eb8a5a0e40e23ae5e3cc2a4e92f0353d30b5.zip |
#653 Show errors from other files for mypy
Diffstat (limited to 'ale_linters/python')
-rw-r--r-- | ale_linters/python/mypy.vim | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/ale_linters/python/mypy.vim b/ale_linters/python/mypy.vim index 1d4efe89..6884a9ac 100644 --- a/ale_linters/python/mypy.vim +++ b/ale_linters/python/mypy.vim @@ -10,14 +10,22 @@ function! ale_linters#python#mypy#GetExecutable(buffer) abort return ale#python#FindExecutable(a:buffer, 'python_mypy', ['mypy']) endfunction -function! ale_linters#python#mypy#GetCommand(buffer) abort +" The directory to change to before running mypy +function! s:GetDir(buffer) abort let l:project_root = ale#python#FindProjectRoot(a:buffer) - let l:cd_command = !empty(l:project_root) - \ ? ale#path#CdString(l:project_root) - \ : '' + + return !empty(l:project_root) + \ ? l:project_root + \ : expand('#' . a:buffer . ':p:h') +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) - return l:cd_command + " 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) \ . ' --show-column-numbers ' \ . ale#Var(a:buffer, 'python_mypy_options') @@ -25,6 +33,7 @@ function! ale_linters#python#mypy#GetCommand(buffer) abort endfunction function! ale_linters#python#mypy#Handle(buffer, lines) abort + let l:dir = s:GetDir(a:buffer) " Look for lines like the following: " " file.py:4: error: No library stub file for module 'django.db' @@ -34,17 +43,13 @@ function! ale_linters#python#mypy#Handle(buffer, lines) abort " file.py:4: note: (Stub files are from https://github.com/python/typeshed) let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?: (error|warning): (.+)$' let l:output = [] - let l:buffer_filename = expand('#' . a:buffer . ':p') for l:match in ale#util#GetMatches(a:lines, l:pattern) - if l:buffer_filename[-len(l:match[1]):] isnot# l:match[1] - continue - endif - call add(l:output, { + \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]), \ 'lnum': l:match[2] + 0, \ 'col': l:match[3] + 0, - \ 'type': l:match[4] =~# 'error' ? 'E' : 'W', + \ 'type': l:match[4] is# 'error' ? 'E' : 'W', \ 'text': l:match[5], \}) endfor |