summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-10-04 18:17:02 +0100
committerw0rp <devw0rp@gmail.com>2016-10-04 18:17:02 +0100
commitbd2f39f21a772bda384c0ebf7bd7fba0d2ce667f (patch)
tree09a5542280df0048175b7b7b9bf13e8b1b99b578 /plugin
parent8c1f0178ed92039fbb800ceb5650867e5f535d95 (diff)
downloadale-bd2f39f21a772bda384c0ebf7bd7fba0d2ce667f.zip
Handle line numbers beyond the end for any linter.
Diffstat (limited to 'plugin')
-rw-r--r--plugin/ale/handlers.vim8
-rw-r--r--plugin/ale/util.vim5
-rw-r--r--plugin/ale/zmain.vim16
3 files changed, 22 insertions, 7 deletions
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] = []