From 1caf58578c6e4b30c18fa56804dd905b5472b460 Mon Sep 17 00:00:00 2001 From: Mathias Fußenegger Date: Sat, 20 Feb 2021 04:20:42 +0100 Subject: lsp: Fix text edits operating on the last line of a document (#13677) `lines` can be empty, in which case `#lines[#lines]` failed with an error: lsp/util.lua:214: attempt to get length of a nil value --- runtime/lua/vim/lsp/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 00bdeecef3..9c5e8ec8c3 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -211,7 +211,7 @@ function M.apply_text_edits(text_edits, bufnr) local lines = api.nvim_buf_get_lines(bufnr, start_line, finish_line + 1, false) local fix_eol = api.nvim_buf_get_option(bufnr, 'fixeol') local set_eol = fix_eol and api.nvim_buf_line_count(bufnr) <= finish_line + 1 - if set_eol and #lines[#lines] ~= 0 then + if set_eol and (#lines == 0 or #lines[#lines] ~= 0) then table.insert(lines, '') end -- cgit