Skip to content

Commit 279c1ad

Browse files
committed
clear node cache after scope diagnosing
#1626
1 parent 12809be commit 279c1ad

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

script/provider/diagnostic.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local vm = require 'vm.vm'
2323
local m = {}
2424
m.cache = {}
2525
m.sleepRest = 0.0
26+
m.scopeDiagCount = 0
2627

2728
local function concat(t, sep)
2829
if type(t) ~= 'table' then
@@ -466,6 +467,14 @@ local function askForDisable(uri)
466467
end
467468
end
468469

470+
local function clearMemory()
471+
if m.scopeDiagCount > 0 then
472+
return
473+
end
474+
vm.clearNodeCache()
475+
collectgarbage()
476+
end
477+
469478
---@async
470479
function m.awaitDiagnosticsScope(suri, callback)
471480
local scp = scope.getScope(suri)
@@ -475,6 +484,11 @@ function m.awaitDiagnosticsScope(suri, callback)
475484
while loading.count() > 0 do
476485
await.sleep(1.0)
477486
end
487+
m.scopeDiagCount = m.scopeDiagCount + 1
488+
local scopeDiag <close> = util.defer(function ()
489+
m.scopeDiagCount = m.scopeDiagCount - 1
490+
clearMemory()
491+
end)
478492
local clock = os.clock()
479493
local bar <close> = progress.create(suri, lang.script.WORKSPACE_DIAGNOSTIC, 1)
480494
local cancelled

script/vm/vm.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ local mathHuge = math.huge
99

1010
local weakMT = { __mode = 'kv' }
1111

12-
_ENV = nil
13-
1412
---@class vm
1513
local m = {}
1614

0 commit comments

Comments
 (0)