mirror of https://github.com/dense-analysis/ale
Handle line numbers beyond the end for any linter.
This commit is contained in:
parent
8c1f0178ed
commit
bd2f39f21a
|
@ -49,12 +49,6 @@ function! ale#handlers#HandleCSSLintFormat(buffer, lines)
|
||||||
" so you can actually read the error type.
|
" so you can actually read the error type.
|
||||||
let pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$'
|
let pattern = '^.*: line \(\d\+\), col \(\d\+\), \(Error\|Warning\) - \(.\+\) (\([^)]\+\))$'
|
||||||
let output = []
|
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
|
for line in a:lines
|
||||||
let l:match = matchlist(line, pattern)
|
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.
|
" vcol is Needed to indicate that the column is a character.
|
||||||
call add(output, {
|
call add(output, {
|
||||||
\ 'bufnr': a:buffer,
|
\ 'bufnr': a:buffer,
|
||||||
\ 'lnum': min([l:match[1] + 0, last_line_number]),
|
\ 'lnum': l:match[1] + 0,
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
\ 'col': l:match[2] + 0,
|
\ 'col': l:match[2] + 0,
|
||||||
\ 'text': text,
|
\ 'text': text,
|
||||||
|
|
|
@ -19,3 +19,8 @@ function! s:FindWrapperScript()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let g:ale#util#stdin_wrapper = s:FindWrapperScript()
|
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
|
||||||
|
|
|
@ -93,6 +93,19 @@ function! s:LocItemCompare(left, right)
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
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)
|
function! s:HandleExit(job)
|
||||||
if !has_key(s:job_info_map, a:job)
|
if !has_key(s:job_info_map, a:job)
|
||||||
return
|
return
|
||||||
|
@ -108,6 +121,9 @@ function! s:HandleExit(job)
|
||||||
|
|
||||||
let linter_loclist = s:GetFunction(linter.callback)(buffer, output)
|
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]
|
if g:ale_buffer_should_reset_map[buffer]
|
||||||
let g:ale_buffer_should_reset_map[buffer] = 0
|
let g:ale_buffer_should_reset_map[buffer] = 0
|
||||||
let g:ale_buffer_loclist_map[buffer] = []
|
let g:ale_buffer_loclist_map[buffer] = []
|
||||||
|
|
Loading…
Reference in New Issue