From e86b15b25c70070faf224d97073b6e5c4b032a91 Mon Sep 17 00:00:00 2001 From: Gıyaseddin Tanrıkulu Date: Wed, 2 Sep 2020 06:45:47 +0300 Subject: lsp/make_position_param(): handle empty buffer #12825 Fix #12623 problem: nvim_buf_get_lines(0) returns empty during startup, where no buffers are loaded yet. solution: return empty object Happens during startup, where buffer may not be loaded yet, because... `source_startup_scripts()` is done before `edit_buffers()`: https://github.com/neovim/neovim/blob/9bb552875d205d2f869c66137563f93b77a6d08e/src/nvim/main.c#L362 https://github.com/neovim/neovim/blob/9bb552875d205d2f869c66137563f93b77a6d08e/src/nvim/main.c#L480 --- runtime/lua/vim/lsp/util.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index cedb0b2824..24cb454e5b 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1437,6 +1437,9 @@ local function make_position_param() local row, col = unpack(api.nvim_win_get_cursor(0)) row = row - 1 local line = api.nvim_buf_get_lines(0, row, row+1, true)[1] + if not line then + return { line = 0; character = 0; } + end col = str_utfindex(line, col) return { line = row; character = col; } end -- cgit