diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 21:13:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 21:13:58 +0800 |
commit | 4c71c56f925246618cce854ab9773311a7812055 (patch) | |
tree | 45721d5321668cf5b749caab322a84b414e587fb /script/workspace/scope.lua | |
parent | d50a75aac341d6b87caadb3eb9b863cb8ebe2751 (diff) | |
download | lua-language-server-4c71c56f925246618cce854ab9773311a7812055.zip |
support change workspace folders
TODO: has memory leak after remove folders
Diffstat (limited to 'script/workspace/scope.lua')
-rw-r--r-- | script/workspace/scope.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua index a81d638c..4649d354 100644 --- a/script/workspace/scope.lua +++ b/script/workspace/scope.lua @@ -11,6 +11,7 @@ local m = {} ---@field _links table<uri, boolean> ---@field _data table<string, any> ---@field _gc gc +---@field _removed? true local mt = {} mt.__index = mt @@ -117,9 +118,30 @@ end function mt:flushGC() self._gc:remove() + if self._removed then + return + end self._gc = gc() end +function mt:remove() + if self._removed then + return + end + self._removed = true + for i, scp in ipairs(m.folders) do + if scp == self then + table.remove(m.folders, i) + break + end + end + self:flushGC() +end + +function mt:isRemoved() + return self._removed == true +end + ---@param scopeType scope.type ---@return scope local function createScope(scopeType) |