mirror of
https://github.com/neovim/neovim.git
synced 2026-02-20 10:28:33 +00:00
refactor(lsp): drop once(), use _memoize() #37829
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user