summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/engine.vim16
-rw-r--r--autoload/ale/util.vim10
2 files changed, 25 insertions, 1 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index dd871c36..0704fd5b 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -393,7 +393,7 @@ function! ale#engine#FixLocList(buffer, linter_name, loclist) abort
\ 'text': l:old_item.text,
\ 'lnum': str2nr(l:old_item.lnum),
\ 'col': str2nr(get(l:old_item, 'col', 0)),
- \ 'vcol': get(l:old_item, 'vcol', 0),
+ \ 'vcol': 0,
\ 'type': get(l:old_item, 'type', 'E'),
\ 'nr': get(l:old_item, 'nr', -1),
\ 'linter_name': a:linter_name,
@@ -453,6 +453,20 @@ function! ale#engine#FixLocList(buffer, linter_name, loclist) abort
" When errors go beyond the end of the file, put them at the end.
" This is only done for the current buffer.
let l:item.lnum = l:last_line_number
+ elseif get(l:old_item, 'vcol', 0)
+ " Convert virtual column positions to byte positions.
+ " The positions will be off if the buffer has changed recently.
+ let l:line = getbufline(a:buffer, l:item.lnum)[0]
+
+ let l:item.col = ale#util#Col(l:line, l:item.col)
+
+ if has_key(l:item, 'end_col')
+ let l:end_line = get(l:item, 'end_lnum', l:line) != l:line
+ \ ? getbufline(a:buffer, l:item.end_lnum)[0]
+ \ : l:line
+
+ let l:item.end_col = ale#util#Col(l:end_line, l:item.end_col)
+ endif
endif
call add(l:new_loclist, l:item)
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index b94a11b7..e0b31e2c 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -311,3 +311,13 @@ function! ale#util#StopPartialTimer(timer_id) abort
call remove(s:partial_timers, a:timer_id)
endif
endfunction
+
+" Given a possibly multi-byte string and a 1-based character position on a
+" line, return the 1-based byte position on that line.
+function! ale#util#Col(str, chr) abort
+ if a:chr < 2
+ return a:chr
+ endif
+
+ return strlen(join(split(a:str, '\zs')[0:a:chr - 2], '')) + 1
+endfunction