summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-22 11:22:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-22 11:22:30 +0800
commitc0cb126d73007c618e2887776a04f94882ad6021 (patch)
tree84a71e3b95c77e05de059eb4384992566d024ff4 /server
parent3cb5179696f5a12cdb00de84829faaf2a69a84ce (diff)
downloadlua-language-server-c0cb126d73007c618e2887776a04f94882ad6021.zip
内存占用过高自动重启
Diffstat (limited to 'server')
-rw-r--r--server/locale/en-US/script.lni3
-rw-r--r--server/locale/zh-CN/script.lni3
-rw-r--r--server/src/method/workspace/didChangeWorkspaceFolders.lua3
-rw-r--r--server/src/service.lua22
4 files changed, 31 insertions, 0 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni
index ee7d6470..d706a304 100644
--- a/server/locale/en-US/script.lni
+++ b/server/locale/en-US/script.lni
@@ -39,3 +39,6 @@ PARSER_NO_VISIBLE_LABEL = 'No visible label `{label}` .'
PARSER_REDEFINE_LABEL = 'Label `{label}` already defined.'
SYMBOL_ANONYMOUS = '<Anonymous>'
+
+DEBUG_MEMORY_LEAK = "{} I'm sorry for the serious memory leak. The language service will be restarted soon."
+DEBUG_RESTART_NOW = 'Restart now'
diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni
index 3783f1ae..d54b4101 100644
--- a/server/locale/zh-CN/script.lni
+++ b/server/locale/zh-CN/script.lni
@@ -39,3 +39,6 @@ PARSER_NO_VISIBLE_LABEL = '标签`{label}`不可见。'
PARSER_REDEFINE_LABEL = '标签`{label}`重复定义。'
SYMBOL_ANONYMOUS = '<匿名函数>'
+
+DEBUG_MEMORY_LEAK = '{} 很抱歉发生了严重的内存泄漏,语言服务即将重启。'
+DEBUG_RESTART_NOW = '立即重启'
diff --git a/server/src/method/workspace/didChangeWorkspaceFolders.lua b/server/src/method/workspace/didChangeWorkspaceFolders.lua
index dc8bb4a1..01a28abd 100644
--- a/server/src/method/workspace/didChangeWorkspaceFolders.lua
+++ b/server/src/method/workspace/didChangeWorkspaceFolders.lua
@@ -14,4 +14,7 @@ return function ()
}, function ()
os.exit(true)
end)
+ ac.wait(5, function ()
+ os.exit(true)
+ end)
end
diff --git a/server/src/service.lua b/server/src/service.lua
index 4b9d4319..f0cf6489 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -590,6 +590,28 @@ function mt:_testMemory()
alivedSource,
deadSource
))
+
+ -- 内存过高时暴力结束服务释放内存
+ if mem > 1500000 then
+ collectgarbage()
+ mem = collectgarbage 'count'
+ if mem > 1500000 then
+ rpc:requestWait('window/showMessageRequest', {
+ type = 3,
+ message = lang.script('DEBUG_MEMORY_LEAK', '[Lua]'),
+ actions = {
+ {
+ title = lang.script.DEBUG_RESTART_NOW,
+ }
+ }
+ }, function ()
+ os.exit(true)
+ end)
+ ac.wait(5, function ()
+ os.exit(true)
+ end)
+ end
+ end
end
function mt:onTick()