diff options
author | Andrea Cappuccio <hood@null.net> | 2021-08-10 20:52:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-10 20:52:30 +0200 |
commit | adebbebdd7992b72aa74149d51bcb28a936bf45d (patch) | |
tree | de78d416b4d406a44df5f1ee2123984e5847b873 | |
parent | c5baba065c480a1bb83388233f2f35104dd4a2f0 (diff) | |
download | rneovim-adebbebdd7992b72aa74149d51bcb28a936bf45d.tar.gz rneovim-adebbebdd7992b72aa74149d51bcb28a936bf45d.tar.bz2 rneovim-adebbebdd7992b72aa74149d51bcb28a936bf45d.zip |
fix(lsp): properly handle `nil` lines when trimming empty lines (#15325)
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 4 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index f969d4a8d9..d682fdc17e 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1719,14 +1719,14 @@ end function M.trim_empty_lines(lines) local start = 1 for i = 1, #lines do - if #lines[i] > 0 then + if lines[i] ~= nil and #lines[i] > 0 then start = i break end end local finish = 1 for i = #lines, 1, -1 do - if #lines[i] > 0 then + if lines[i] ~= nil and #lines[i] > 0 then finish = i break end diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index b77a285379..863176bfa9 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -1954,6 +1954,12 @@ describe('LSP', function() end) end) + describe('lsp.util.trim.trim_empty_lines', function() + it('properly trims empty lines', function() + eq({{"foo", "bar"}}, exec_lua[[ return vim.lsp.util.trim_empty_lines({{ "foo", "bar" }, nil}) ]]) + end) + end) + describe('lsp.util.get_effective_tabstop', function() local function test_tabstop(tabsize, softtabstop) exec_lua(string.format([[ |