From bd2f39f21a772bda384c0ebf7bd7fba0d2ce667f Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 4 Oct 2016 18:17:02 +0100 Subject: Handle line numbers beyond the end for any linter. --- plugin/ale/handlers.vim | 8 +------- plugin/ale/util.vim | 5 +++++ plugin/ale/zmain.vim | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'plugin') diff --git a/plugin/ale/handlers.vim b/plugin/ale/handlers.vim index afdb67a9..fd0a1b85 100644 --- a/plugin/ale/handlers.vim +++ b/plugin/ale/handlers.vim @@ -49,12 +49,6 @@ function! ale#handlers#HandleCSSLintFormat(buffer, lines) " so you can actually read the error type. let pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$' let output = [] - " Some errors have line numbers beyond the end of the file, - " so we need to adjust them so they set the error at the last line - " of the file instead. - " - " TODO: Find a faster way to compute this. - let last_line_number = len(getbufline(a:buffer, 1, '$')) for line in a:lines let l:match = matchlist(line, pattern) @@ -74,7 +68,7 @@ function! ale#handlers#HandleCSSLintFormat(buffer, lines) " vcol is Needed to indicate that the column is a character. call add(output, { \ 'bufnr': a:buffer, - \ 'lnum': min([l:match[1] + 0, last_line_number]), + \ 'lnum': l:match[1] + 0, \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': text, diff --git a/plugin/ale/util.vim b/plugin/ale/util.vim index cda7a7db..64dd59dc 100644 --- a/plugin/ale/util.vim +++ b/plugin/ale/util.vim @@ -19,3 +19,8 @@ function! s:FindWrapperScript() endfunction let g:ale#util#stdin_wrapper = s:FindWrapperScript() + +" Return the number of lines for a given buffer. +function! ale#util#GetLineCount(buffer) + return len(getbufline(a:buffer, 1, '$')) +endfunction diff --git a/plugin/ale/zmain.vim b/plugin/ale/zmain.vim index 347a1dee..0bf6a1bb 100644 --- a/plugin/ale/zmain.vim +++ b/plugin/ale/zmain.vim @@ -93,6 +93,19 @@ function! s:LocItemCompare(left, right) return 0 endfunction +function! s:FixLoclist(buffer, loclist) + " Some errors have line numbers beyond the end of the file, + " so we need to adjust them so they set the error at the last line + " of the file instead. + let last_line_number = ale#util#GetLineCount(a:buffer) + + for item in a:loclist + if item.lnum > last_line_number + let item.lnum = last_line_number + endif + endfor +endfunction + function! s:HandleExit(job) if !has_key(s:job_info_map, a:job) return @@ -108,6 +121,9 @@ function! s:HandleExit(job) let linter_loclist = s:GetFunction(linter.callback)(buffer, output) + " Make some adjustments to the loclists to fix common problems. + call s:FixLoclist(buffer, linter_loclist) + if g:ale_buffer_should_reset_map[buffer] let g:ale_buffer_should_reset_map[buffer] = 0 let g:ale_buffer_loclist_map[buffer] = [] -- cgit v1.2.3