diff --git a/runtime/lua/vim/func.lua b/runtime/lua/vim/func.lua index 47067ec4b9..654f2e6299 100644 --- 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 index db17f992ba..cfa3d04461 100644 --- 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)