Add linting with eslint in NeoVim, with a few bugs.

This commit is contained in:
w0rp
2016-09-09 00:23:26 +01:00
commit 11c11e578f
8 changed files with 420 additions and 0 deletions

72
plugin/ale/cursor.vim Normal file
View File

@@ -0,0 +1,72 @@
if exists('g:loaded_ale_cursor')
finish
endif
let g:loaded_ale_cursor = 1
" This function will perform a binary search to find a message from the
" loclist to echo when the cursor moves.
function! s:BinarySearch(loclist, line, column)
let min = 0
let max = len(a:loclist) - 1
let last_column_match = -1
while 1
if max < min
return last_column_match
endif
let mid = (min + max) / 2
let obj = a:loclist[mid]
" Binary search to get on the same line
if a:loclist[mid]['lnum'] < a:line
let min = mid + 1
elseif a:loclist[mid]['lnum'] > a:line
let max = mid - 1
else
let last_column_match = mid
" Binary search to get the same column, or near it
if a:loclist[mid]['col'] < a:column
let min = mid + 1
elseif a:loclist[mid]['col'] > a:column
let max = mid - 1
else
return mid
endif
endif
endwhile
endfunction
function! ale#cursor#TruncatedEcho(message)
let message = a:message
" Change tabs to spaces.
let message = substitute(message, "\t", ' ', 'g')
" Remove any newlines in the message.
let message = substitute(message, "\n", '', 'g')
let truncated_message = join(split(message, '\zs')[:&columns - 2], '')
" Echo the message truncated to fit without creating a prompt.
echo truncated_message
endfunction
function! ale#cursor#EchoCursorWarning()
let pos = getcurpos()
let index = s:BinarySearch(b:ale_loclist, pos[1], pos[2])
if index >= 0
call ale#cursor#TruncatedEcho(b:ale_loclist[index]['text'])
else
echo
endif
endfunction
if g:ale_echo_cursor
augroup ALECursorGroup
autocmd!
autocmd CursorMoved * call ale#cursor#EchoCursorWarning()
augroup END
endif