summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-09 17:25:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-09 17:25:23 +0800
commita779b7dbbbfbd4a5a177ba44f0db131d1ce3c6a6 (patch)
treeb0ce64e12ddcbf7f564a08d162138341fe7fca86 /script
parentd1b6b518a28170b13ba1d83bd39a3c23efac04fd (diff)
downloadlua-language-server-a779b7dbbbfbd4a5a177ba44f0db131d1ce3c6a6.zip
do full gc after scope diag
#1745
Diffstat (limited to 'script')
-rw-r--r--script/provider/diagnostic.lua10
-rw-r--r--script/provider/provider.lua4
2 files changed, 12 insertions, 2 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index fd78b9c2..90c5a81c 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -508,11 +508,15 @@ local function askForDisable(uri)
end
end
-local function clearMemory()
+local function clearMemory(finished)
if m.scopeDiagCount > 0 then
return
end
vm.clearNodeCache()
+ if finished then
+ collectgarbage()
+ collectgarbage()
+ end
end
---@async
@@ -524,10 +528,11 @@ function m.awaitDiagnosticsScope(suri, callback)
while loading.count() > 0 do
await.sleep(1.0)
end
+ local finished
m.scopeDiagCount = m.scopeDiagCount + 1
local scopeDiag <close> = util.defer(function ()
m.scopeDiagCount = m.scopeDiagCount - 1
- clearMemory()
+ clearMemory(finished)
end)
local clock = os.clock()
local bar <close> = progress.create(suri, lang.script.WORKSPACE_DIAGNOSTIC, 1)
@@ -567,6 +572,7 @@ function m.awaitDiagnosticsScope(suri, callback)
end
bar:remove()
log.info(('Diagnostics scope [%s] finished, takes [%.3f] sec.'):format(scp:getName(), os.clock() - clock))
+ finished = true
end
function m.diagnosticsScope(uri, force)
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index d7c5c655..319d00a9 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -1159,6 +1159,7 @@ m.register '$/status/click' {
titleDiagnostic,
DEVELOP and 'Restart Server' or nil,
DEVELOP and 'Clear Node Cache' or nil,
+ DEVELOP and 'GC' or nil,
})
if not result then
return
@@ -1177,6 +1178,9 @@ m.register '$/status/click' {
vm.clearNodeCache()
collectgarbage()
collectgarbage()
+ elseif result == 'GC' then
+ collectgarbage()
+ collectgarbage()
end
end
}