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>
This commit is contained in:
Ilia Choly
2024-06-14 05:03:58 -04:00
committed by GitHub
parent 81b372fecd
commit 0a9c81d709
5 changed files with 33 additions and 26 deletions

View File

@@ -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