summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-24 18:08:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-24 18:08:01 +0800
commit7cb37a0ef7f9cb9ec429cd29e770b7bc6e72a2aa (patch)
treecbf3fc8e3783ddb02446473a6d8f007d9d915f26
parent5dae895f67bf0f75278d25b0d412e00705386fce (diff)
downloadlua-language-server-7cb37a0ef7f9cb9ec429cd29e770b7bc6e72a2aa.zip
improve memory usage
-rw-r--r--changelog.md1
-rw-r--r--script/core/infer.lua10
-rw-r--r--script/core/noder.lua16
-rw-r--r--script/core/searcher.lua10
-rw-r--r--test/hover/init.lua6
5 files changed, 31 insertions, 12 deletions
diff --git a/changelog.md b/changelog.md
index 6cd66dc6..a73512e7 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 2.0.3
+* `CHG` improve memory usage
* `FIX` some dialog boxes block the initialization process
## 2.0.2
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 1111cb55..2d791bc0 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -135,12 +135,12 @@ local function searchInferOfValue(value, infers, mark)
end
return true
end
+ if value.type == 'integer' then
+ infers['integer'] = true
+ return true
+ end
if value.type == 'number' then
- if math.type(value[1]) == 'integer' then
- infers['integer'] = true
- else
- infers['number'] = true
- end
+ infers['number'] = true
return true
end
if value.type == 'nil' then
diff --git a/script/core/noder.lua b/script/core/noder.lua
index c7963618..20b2655a 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -122,12 +122,12 @@ local function getKey(source)
elseif source.type == 'function' then
return source.start, nil
elseif source.type == 'string' then
- return source.start, nil
+ return '', nil
elseif source.type == 'integer'
or source.type == 'number'
or source.type == 'boolean'
or source.type == 'nil' then
- return source.start, nil
+ return '', nil
elseif source.type == '...' then
return source.start, nil
elseif source.type == 'varargs' then
@@ -446,6 +446,13 @@ function m.pushSource(noders, source, id)
if not id then
return
end
+ if id == 'str:'
+ or id == 'nil:'
+ or id == 'num:'
+ or id == 'int:'
+ or id == 'bool:' then
+ return
+ end
local node = getNode(noders, id)
if not node.source then
node.source = source
@@ -523,7 +530,10 @@ local function bindValue(noders, source, id)
-- x = y : x -> y
pushForward(noders, id, valueID, 'set')
-- 参数/call禁止反向查找赋值
- local valueType = valueID:match '^.-:'
+ local valueType = valueID:match '^(.-:).'
+ if not valueType then
+ return
+ end
if valueType ~= 'p:'
and valueType ~= 's:'
and valueType ~= 'c:' then
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 7d728cb3..effbdab4 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -10,6 +10,14 @@ local collector = require 'core.collector'
local NONE = {'NONE'}
local LAST = {'LAST'}
+local ignoredSources = {
+ ['int:'] = true,
+ ['num:'] = true,
+ ['str:'] = true,
+ ['bool:'] = true,
+ ['nil:'] = true,
+}
+
local ignoredIDs = {
['dn:unknown'] = true,
['dn:nil'] = true,
@@ -571,7 +579,7 @@ function m.searchRefsByID(status, uri, expect, mode)
if node.call then
callStack[#callStack+1] = node.call
end
- if field == nil and node.source then
+ if field == nil and node.source and not ignoredSources[id] then
noder.eachSource(node, function (source)
local force = genericCallArgs[source]
m.pushResult(status, mode, source, force)
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 26064b5f..ff33944b 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -614,7 +614,7 @@ end
local <?r?> = a(1)
]]
[[
-local r: string = "a"
+local r: string
]]
TEST[[
@@ -624,7 +624,7 @@ end
local _, <?r?> = pcall(a, 1)
]]
[[
-local r: string = "a"
+local r: string
]]
TEST[[
@@ -1049,7 +1049,7 @@ end
local <?r?> = f(1)
]]
[[
-local r: integer = 1
+local r: integer
]]
TEST [[