diff options
author | sumneko <sumneko@hotmail.com> | 2022-02-08 19:29:44 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-02-08 19:52:17 +0800 |
commit | 01fbaf633deb9494c0b72906e71bac9f73b318ae (patch) | |
tree | 7cb611771478feeb947ee248d8f681f3ebd16c8e /script/workspace | |
parent | 9bce8c2f953d63e7bcb4d847363b5bfd468bd403 (diff) | |
download | lua-language-server-01fbaf633deb9494c0b72906e71bac9f73b318ae.zip |
cleanup
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/scope.lua | 13 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 11 |
2 files changed, 15 insertions, 9 deletions
diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index ab9c3fb9..be112af2 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -1,3 +1,5 @@ +local gc = require 'gc' + ---@alias scope.type '"override"'|'"folder"'|'"fallback"' ---@class scope @@ -5,6 +7,7 @@ ---@field uri? uri ---@field _links table<uri, boolean> ---@field _data table<string, any> +---@field _gc gc local mt = {} mt.__index = mt @@ -97,6 +100,15 @@ function mt:getName() return self.uri or ('<' .. self.type .. '>') end +function mt:gc(obj) + self._gc:add(obj) +end + +function mt:flushGC() + self._gc:remove() + self._gc = gc() +end + ---@param scopeType scope.type ---@return scope local function createScope(scopeType) @@ -104,6 +116,7 @@ local function createScope(scopeType) type = scopeType, _links = {}, _data = {}, + _gc = gc(), }, mt) return scope diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index fc146fc1..e53ba525 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -267,14 +267,7 @@ function m.awaitPreload(scp) await.setID('preload:' .. scp:getName()) await.sleep(0.1) - local watchers = scp:get 'watchers' - if watchers then - for _, dispose in ipairs(watchers) do - dispose() - end - end - watchers = {} - scp:set('watchers', watchers) + scp:flushGC() local ld <close> = loading.create(scp) scp:set('loading', ld) @@ -301,7 +294,7 @@ function m.awaitPreload(scp) scp:get('cachedUris')[furi.encode(path)] = true ld:loadFile(furi.encode(path), libMatcher.uri) end) - watchers[#watchers+1] = fw.watch(furi.decode(libMatcher.uri)) + scp:gc(fw.watch(furi.decode(libMatcher.uri))) end -- must wait for other scopes to add library |