Skip to content

Commit 680b86f

Browse files
jflymochaaP
andauthored
feature: clear cache when stopping lsp client (#199)
Co-authored-by: Zephyr Lykos <[email protected]>
1 parent fc2af03 commit 680b86f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lua/null-ls/helpers/cache.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ local next_key = 0
22

33
local M = {}
44

5-
M.cache = {}
5+
M._reset = function()
6+
M.cache = {}
7+
end
8+
9+
M._reset()
610

711
--- creates a function that caches the output of a callback, indexed by bufnr
812
---@param cb function
913
---@return fun(params: NullLsParams): any
1014
M.by_bufnr = function(cb)
1115
-- assign next available key, since we just want to avoid collisions
1216
local key = next_key
13-
M.cache[key] = {}
1417
next_key = next_key + 1
1518

1619
return function(params)
1720
local bufnr = params.bufnr
21+
22+
if M.cache[key] == nil then
23+
M.cache[key] = {}
24+
end
25+
1826
-- if we haven't cached a value yet, get it from cb
1927
if M.cache[key][bufnr] == nil then
2028
-- make sure we always store a value so we know we've already called cb
@@ -25,8 +33,4 @@ M.by_bufnr = function(cb)
2533
end
2634
end
2735

28-
M._reset = function()
29-
M.cache = {}
30-
end
31-
3236
return M

lua/null-ls/rpc.lua

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local c = require("null-ls.config")
22
local log = require("null-ls.logger")
33
local methods = require("null-ls.methods")
4+
local cache = require("null-ls.helpers").cache
45

56
local notification_cache = {}
67

@@ -151,6 +152,7 @@ M.start = function(dispatchers)
151152
return stopped
152153
end,
153154
terminate = function()
155+
cache._reset()
154156
stopped = true
155157
end,
156158
}

0 commit comments

Comments
 (0)