diff options
author | Ilia Choly <ilia.choly@gmail.com> | 2024-06-14 05:03:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 11:03:58 +0200 |
commit | 0a9c81d70964f905112857900fbaa6aae590a96d (patch) | |
tree | f37d9869cdbf88ae90d707daf2a1fa00ea2e52f8 /runtime/lua/vim/lsp/util.lua | |
parent | 81b372fecd749d350fbd86be1f65146b2df97b70 (diff) | |
download | rneovim-0a9c81d70964f905112857900fbaa6aae590a96d.tar.gz rneovim-0a9c81d70964f905112857900fbaa6aae590a96d.tar.bz2 rneovim-0a9c81d70964f905112857900fbaa6aae590a96d.zip |
refactor(lsp): use metatable for buf_versions (#29304)
This reduces the number of nil checks around buf_versions usage
Test changes were lifted from 5c33815
Co-authored-by: Mathias Fussenegger <f.mathias@zignar.net>
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index ae6de591b3..a5cf13ed0f 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -516,7 +516,6 @@ function M.apply_text_document_edit(text_document_edit, index, offset_encoding) and ( text_document.version and text_document.version > 0 - and M.buf_versions[bufnr] and M.buf_versions[bufnr] > text_document.version ) then @@ -2222,6 +2221,11 @@ end M._get_line_byte_from_position = get_line_byte_from_position ---@nodoc -M.buf_versions = {} ---@type table<integer,integer> +---@type table<integer,integer> +M.buf_versions = setmetatable({}, { + __index = function(t, bufnr) + return rawget(t, bufnr) or 0 + end, +}) return M |