commit fd69b7111912ae5ccb01327b130f582be23e44dc
parent 16da47f4749b49660d85b3d00aaa00d66098027f
Author: Justin M. Keyes <justinkz@gmail.com>
Date: Thu, 12 Feb 2026 07:15:20 -0500
refactor(lsp): drop once(), use _memoize() #37829
Diffstat:
2 files changed, 4 insertions(+), 27 deletions(-)
diff --git a/runtime/lua/vim/func.lua b/runtime/lua/vim/func.lua
@@ -24,13 +24,10 @@ local M = {}
--- @generic F: function
--- @param hash integer|string|function Hash function to create a hash to use as a key to
--- store results. Possible values:
---- - When integer, refers to the index of an argument of {fn} to hash.
---- This argument can have any type.
+--- - When integer, refers to the index of a {fn} argument (of any type) to hash.
--- - When function, is evaluated using the same arguments passed to {fn}.
---- - When `concat`, the hash is determined by string concatenating all the
---- arguments passed to {fn}.
---- - When `concat-n`, the hash is determined by string concatenating the
---- first n arguments passed to {fn}.
+--- - When "concat", hash is determined by string-concatenating all {fn} arguments.
+--- - When "concat-n", hash is determined by string-concatenating the first n {fn} arguments.
---
--- @param fn F Function to memoize.
--- @param weak? boolean Use a weak table (default `true`)
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
@@ -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)