summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-09 16:21:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-09 16:21:05 +0800
commita0b38e22f3c20c2cff737d489c12eee740c9f6f5 (patch)
treec0fc93539ffc660b298f0245791ab79209b20996
parent729073ec3619cde7c6be8102bc6e390f83d0dffd (diff)
downloadlua-language-server-a0b38e22f3c20c2cff737d489c12eee740c9f6f5.zip
优化一下大文件诊断的响应
-rw-r--r--script-beta/vm/eachRef.lua20
-rw-r--r--script-beta/vm/getLibrary.lua13
-rw-r--r--script-beta/vm/getValue.lua4
3 files changed, 25 insertions, 12 deletions
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index f4804a77..972efc2d 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -536,10 +536,17 @@ function vm.isSameRef(a, b)
end
--- 获取所有的引用
-function vm.eachRef(source, callback)
+function vm.eachRef(source, callback, max)
local cache = vm.cache.eachRef[source]
if cache then
- for i = 1, #cache do
+ if max then
+ if max > #cache then
+ max = #cache
+ end
+ else
+ max = #cache
+ end
+ for i = 1, max do
local res = callback(cache[i])
if res ~= nil then
return res
@@ -567,7 +574,14 @@ function vm.eachRef(source, callback)
local src = cache[i].source
vm.cache.eachRef[src] = cache
end
- for i = 1, #cache do
+ if max then
+ if max > #cache then
+ max = #cache
+ end
+ else
+ max = #cache
+ end
+ for i = 1, max do
local res = callback(cache[i])
if res ~= nil then
return res
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index d2f88116..69280fd9 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -71,13 +71,12 @@ local function checkNode(source)
end
local function getLibrary(source)
- local lib = checkStdLibrary(source)
- if lib then
- return lib
- end
- return checkNode(source) or vm.eachRef(source, function (info)
- return checkStdLibrary(info.source) or checkNode(info.source)
- end)
+ return checkNode(source)
+ or checkStdLibrary(source)
+ or vm.eachRef(source, function (info)
+ return checkStdLibrary(info.source)
+ or checkNode(info.source)
+ end, 100)
end
function vm.getLibrary(source)
diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua
index bde3fad2..a93ed6e9 100644
--- a/script-beta/vm/getValue.lua
+++ b/script-beta/vm/getValue.lua
@@ -682,7 +682,7 @@ end
local function inferBySetOfLocal(results, source)
if source.ref then
- for i = 1, #source.ref do
+ for i = 1, math.min(#source.ref, 100) do
local ref = source.ref[i]
if ref.type == 'setlocal' then
break
@@ -700,7 +700,7 @@ local function inferBySet(results, source)
inferBySetOfLocal(results, source)
elseif source.type == 'setlocal'
or source.type == 'getlocal' then
- inferBySetOfLocal(results, source.node)
+ merge(results, vm.getValue(source.node))
end
end