summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-18 21:54:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-18 21:54:30 +0800
commit138adf804985b0343f15c1d8c464bdb1c2b6c69d (patch)
tree8334ac853f77cff51eb6a27a3bcfe1956f340bbc /script-beta
parent520b0b8e8b480fce1dd4152a5d8d519653863778 (diff)
downloadlua-language-server-138adf804985b0343f15c1d8c464bdb1c2b6c69d.zip
优化性能
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/diagnostics/undefined-global.lua16
-rw-r--r--script-beta/parser/guide.lua10
-rw-r--r--script-beta/vm/getGlobals.lua16
3 files changed, 29 insertions, 13 deletions
diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua
index 69d43d45..e287fefa 100644
--- a/script-beta/core/diagnostics/undefined-global.lua
+++ b/script-beta/core/diagnostics/undefined-global.lua
@@ -11,7 +11,6 @@ return function (uri, callback)
return
end
- local globalCache = vm.getCache('undefined-global')
-- 遍历全局变量,检查所有没有 set 模式的全局变量
guide.eachSourceType(ast.ast, 'getglobal', function (src)
local key = guide.getName(src)
@@ -21,20 +20,11 @@ return function (uri, callback)
if config.config.diagnostics.globals[key] then
return
end
- if globalCache[key] == nil then
- globalCache[key] = false
- local refs = vm.getGlobals(key)
- for _, ref in pairs(refs) do
- if vm.isSet(ref) then
- globalCache[key] = true
- break
- end
- end
- end
- if globalCache[key] then
+ if library.global[key] then
return
end
- if library.global[key] then
+ local sets = vm.getGlobalSets(guide.getKeyName(src))
+ if #sets > 0 then
return
end
local message = lang.script('DIAG_UNDEF_GLOBAL', key)
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index c766a977..13388a34 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1014,6 +1014,16 @@ function m.copyStatusResults(a, b)
end
end
+function m.isGlobal(source)
+ if source.type == 'setglobal'
+ or source.type == 'getglobal' then
+ if source.node.tag == '_ENV' then
+ return true
+ end
+ end
+ return false
+end
+
--- 根据函数的调用参数,获取:调用,参数索引
function m.getCallAndArgIndex(callarg)
local callargs = callarg.parent
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua
index 16dce873..c6651048 100644
--- a/script-beta/vm/getGlobals.lua
+++ b/script-beta/vm/getGlobals.lua
@@ -62,3 +62,19 @@ function vm.getGlobals(name)
vm.getCache('getGlobals')[name] = cache
return cache
end
+
+function vm.getGlobalSets(name)
+ local cache = vm.getCache('getGlobalDefs')[name]
+ if cache ~= nil then
+ return cache
+ end
+ cache = {}
+ local refs = getGlobals(name)
+ for _, source in ipairs(refs) do
+ if vm.isSet(source) then
+ cache[#cache+1] = source
+ end
+ end
+ vm.getCache('getGlobals')[name] = cache
+ return cache
+end