refactor(lsp): drop once(), use _memoize() #37829

This commit is contained in:
Justin M. Keyes
2026-02-12 07:15:20 -05:00
committed by GitHub
parent 16da47f474
commit fd69b71119
2 changed files with 4 additions and 27 deletions

View File

@@ -113,26 +113,6 @@ function lsp._buf_get_full_text(bufnr)
return text
end
--- Memoizes a function. On first run, the function return value is saved and
--- immediately returned on subsequent runs. If the function returns a multival,
--- only the first returned value will be memoized and returned. The function will only be run once,
--- even if it has side effects.
---
---@generic T: function
---@param fn (T) Function to run
---@return T
local function once(fn)
local value --- @type function
local ran = false
return function(...)
if not ran then
value = fn(...) --- @type function
ran = true
end
return value
end
end
--- @param client vim.lsp.Client
--- @param config vim.lsp.ClientConfig
--- @return boolean
@@ -832,7 +812,7 @@ end
local function text_document_did_save_handler(bufnr)
bufnr = vim._resolve_bufnr(bufnr)
local uri = vim.uri_from_bufnr(bufnr)
local text = once(lsp._buf_get_full_text)
local text = vim.func._memoize('concat', lsp._buf_get_full_text)
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
local name = api.nvim_buf_get_name(bufnr)
local old_name = changetracking._get_and_set_name(client, bufnr, name)