summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-05-16 13:44:40 +0100
committerw0rp <devw0rp@gmail.com>2019-05-16 13:44:40 +0100
commit9b89ec3d863f3fa4d24d8597163df98aa5bf2c74 (patch)
tree844b5ed546fef7d2eee37d1a645a5ab904a3d5da
parent4234d39d87c6cdd37eb5f52af58c0454b23843ca (diff)
downloadale-9b89ec3d863f3fa4d24d8597163df98aa5bf2c74.zip
#2505 Try to fix NeoVim highlighting out of range errors
-rw-r--r--autoload/ale/highlight.vim8
1 files changed, 5 insertions, 3 deletions
diff --git a/autoload/ale/highlight.vim b/autoload/ale/highlight.vim
index 172f9d54..f228aa44 100644
--- a/autoload/ale/highlight.vim
+++ b/autoload/ale/highlight.vim
@@ -119,20 +119,22 @@ endfunction
function! s:highlight_range(bufnr, range, group) abort
if ale#highlight#HasNeovimApi()
+ let l:line_count = len(getbufline(a:bufnr, 1, '$'))
+
let l:highlight_id = s:ale_nvim_highlight_id(a:bufnr)
" NOTE: lines and columns indicies are 0-based in nvim_buf_* API.
let l:lnum = a:range.lnum - 1
- let l:end_lnum = a:range.end_lnum - 1
+ let l:end_lnum = min([a:range.end_lnum, l:line_count]) - 1
let l:col = a:range.col - 1
let l:end_col = a:range.end_col
- if l:lnum >= l:end_lnum
+ if l:lnum is l:end_lnum
" For single lines, just return the one position.
call ale#highlight#nvim_buf_add_highlight(
\ a:bufnr, l:highlight_id, a:group,
\ l:lnum, l:col, l:end_col
\)
- else
+ elseif l:lnum < l:end_lnum
" highlight first line from start till the line end
call ale#highlight#nvim_buf_add_highlight(
\ a:bufnr, l:highlight_id, a:group,