Skip to content

Commit a779b7d

Browse files
committed
do full gc after scope diag
#1745
1 parent d1b6b51 commit a779b7d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

script/provider/diagnostic.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,15 @@ local function askForDisable(uri)
508508
end
509509
end
510510

511-
local function clearMemory()
511+
local function clearMemory(finished)
512512
if m.scopeDiagCount > 0 then
513513
return
514514
end
515515
vm.clearNodeCache()
516+
if finished then
517+
collectgarbage()
518+
collectgarbage()
519+
end
516520
end
517521

518522
---@async
@@ -524,10 +528,11 @@ function m.awaitDiagnosticsScope(suri, callback)
524528
while loading.count() > 0 do
525529
await.sleep(1.0)
526530
end
531+
local finished
527532
m.scopeDiagCount = m.scopeDiagCount + 1
528533
local scopeDiag <close> = util.defer(function ()
529534
m.scopeDiagCount = m.scopeDiagCount - 1
530-
clearMemory()
535+
clearMemory(finished)
531536
end)
532537
local clock = os.clock()
533538
local bar <close> = progress.create(suri, lang.script.WORKSPACE_DIAGNOSTIC, 1)
@@ -567,6 +572,7 @@ function m.awaitDiagnosticsScope(suri, callback)
567572
end
568573
bar:remove()
569574
log.info(('Diagnostics scope [%s] finished, takes [%.3f] sec.'):format(scp:getName(), os.clock() - clock))
575+
finished = true
570576
end
571577

572578
function m.diagnosticsScope(uri, force)

script/provider/provider.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ m.register '$/status/click' {
11591159
titleDiagnostic,
11601160
DEVELOP and 'Restart Server' or nil,
11611161
DEVELOP and 'Clear Node Cache' or nil,
1162+
DEVELOP and 'GC' or nil,
11621163
})
11631164
if not result then
11641165
return
@@ -1177,6 +1178,9 @@ m.register '$/status/click' {
11771178
vm.clearNodeCache()
11781179
collectgarbage()
11791180
collectgarbage()
1181+
elseif result == 'GC' then
1182+
collectgarbage()
1183+
collectgarbage()
11801184
end
11811185
end
11821186
}

0 commit comments

Comments
 (0)