diff --git a/autoload/lsp/utils/position.vim b/autoload/lsp/utils/position.vim index 05caa85dd..6868f252b 100644 --- a/autoload/lsp/utils/position.vim +++ b/autoload/lsp/utils/position.vim @@ -12,6 +12,10 @@ function! s:to_col(expr, lnum, char) abort endif " a:expr is a file that is not yet loaded as a buffer let l:lines = readfile(a:expr, '', a:lnum) + if l:lines == [] + " when the file is empty. a:char should be 0 in the case + return a:char + 1 + endif endif let l:linestr = l:lines[-1] return strlen(strcharpart(l:linestr, 0, a:char)) + 1