From f472e04b095565e843490752c0170d32d3ba3ccb Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 14 Jun 2017 10:51:31 +0100 Subject: #538 - Set some end column indexes for flake8 --- autoload/ale/handlers/python.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'autoload') diff --git a/autoload/ale/handlers/python.vim b/autoload/ale/handlers/python.vim index 58e7d757..ba1cc57f 100644 --- a/autoload/ale/handlers/python.vim +++ b/autoload/ale/handlers/python.vim @@ -1,6 +1,13 @@ " Author: w0rp " Description: Error handling for flake8, etc. +let s:end_col_pattern_map = { +\ 'F405': '\(.\+\) may be undefined', +\ 'F821': 'undefined name ''\([^'']\+\)''', +\ 'F999': '^''\([^'']\+\)''', +\ 'F841': 'local variable ''\([^'']\+\)''', +\} + function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort for l:line in a:lines[:10] if match(l:line, '^Traceback') >= 0 @@ -35,12 +42,24 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort continue endif - call add(l:output, { + let l:item = { \ 'lnum': l:match[1] + 0, \ 'col': l:match[2] + 0, \ 'text': l:code . ': ' . l:match[4], \ 'type': l:code[:0] ==# 'E' ? 'E' : 'W', - \}) + \} + + let l:end_col_pattern = get(s:end_col_pattern_map, l:code, '') + + if !empty(l:end_col_pattern) + let l:end_col_match = matchlist(l:match[4], l:end_col_pattern) + + if !empty(l:end_col_match) + let l:item.end_col = l:item.col + len(l:end_col_match[1]) - 1 + endif + endif + + call add(l:output, l:item) endfor return l:output -- cgit v1.2.3