summaryrefslogtreecommitdiff
path: root/server-beta/src/core/diagnostics/undefined-global.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-10 19:03:07 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-10 19:03:07 +0800
commit65e612667dbe0c9529b9a318871f5807754be64d (patch)
treea5b2e81197e3a7e78ba2d1c411339441bf6a7c26 /server-beta/src/core/diagnostics/undefined-global.lua
parentd377cc10623b41f937a45c8be18a2663a42a876c (diff)
downloadlua-language-server-65e612667dbe0c9529b9a318871f5807754be64d.zip
优化全局变量性能
Diffstat (limited to 'server-beta/src/core/diagnostics/undefined-global.lua')
-rw-r--r--server-beta/src/core/diagnostics/undefined-global.lua49
1 files changed, 17 insertions, 32 deletions
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua
index b39803b8..b3ef3044 100644
--- a/server-beta/src/core/diagnostics/undefined-global.lua
+++ b/server-beta/src/core/diagnostics/undefined-global.lua
@@ -10,27 +10,12 @@ return function (uri, callback)
return
end
- -- 先遍历一次该文件中的全局变量
- -- 如果变量有 set 行为,则做标记
- -- 然后再遍历一次,对所有的行为打上相同标记
- local hasSet = {}
- searcher.eachGlobal(ast.ast, function (info)
- if hasSet[info.source] ~= nil then
+ -- 遍历全局变量,检查所有没有 mode['set'] 的全局变量
+ searcher.eachGlobal(ast.ast, function (infos)
+ if infos.mode['set'] == true then
return
end
- local mark = searcher.eachRef(info.source, function (info)
- if info.mode == 'set' then
- return true
- end
- end)
- searcher.eachRef(info.source, function (info)
- hasSet[info.source] = mark
- end)
- end)
- -- 然后再遍历一次,检查所有标记为假的全局变量
- searcher.eachGlobal(ast.ast, function (info)
- local source = info.source
- local key = info.key
+ local key = infos.key
local skey = key and key:match '^s|(.+)$'
if not skey then
return
@@ -41,20 +26,20 @@ return function (uri, callback)
if config.config.diagnostics.globals[skey] then
return
end
- if info.mode == 'get' and not hasSet[source] then
- local message
- local otherVersion = library.other[skey]
- local customVersion = library.custom[skey]
- if otherVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version))
- elseif customVersion then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
- else
- message = lang.script('DIAG_UNDEF_GLOBAL', skey)
- end
+ local message
+ local otherVersion = library.other[skey]
+ local customVersion = library.custom[skey]
+ if otherVersion then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(otherVersion, '/'), config.config.runtime.version))
+ elseif customVersion then
+ message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
+ else
+ message = lang.script('DIAG_UNDEF_GLOBAL', skey)
+ end
+ for _, info in ipairs(infos) do
callback {
- start = source.start,
- finish = source.finish,
+ start = info.source.start,
+ finish = info.source.finish,
message = message,
}
end