summaryrefslogtreecommitdiff
path: root/script-beta/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-25 17:27:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-25 17:27:01 +0800
commit856a4cb27430d6d578a1ee450e7ac4aa13a5f4f1 (patch)
tree356120ae3713e723e8dca5fdae6314b2d3b63676 /script-beta/core/diagnostics
parent64aab1cc575552ce2ed494790d201d3e6f170065 (diff)
downloadlua-language-server-856a4cb27430d6d578a1ee450e7ac4aa13a5f4f1.zip
更新API
Diffstat (limited to 'script-beta/core/diagnostics')
-rw-r--r--script-beta/core/diagnostics/redundant-parameter.lua3
-rw-r--r--script-beta/core/diagnostics/undefined-env-child.lua7
-rw-r--r--script-beta/core/diagnostics/undefined-global.lua27
-rw-r--r--script-beta/core/diagnostics/unused-function.lua10
4 files changed, 30 insertions, 17 deletions
diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua
index 8d486aea..45f8327e 100644
--- a/script-beta/core/diagnostics/redundant-parameter.lua
+++ b/script-beta/core/diagnostics/redundant-parameter.lua
@@ -62,8 +62,7 @@ return function (uri, callback)
local func = source.node
local funcArgs
- vm.eachDef(func, function (info)
- local src = info.source
+ vm.eachDef(func, function (src)
if src.type == 'function' then
local args = countFuncArgs(src)
if not funcArgs or args > funcArgs then
diff --git a/script-beta/core/diagnostics/undefined-env-child.lua b/script-beta/core/diagnostics/undefined-env-child.lua
index df096cb8..a19abb63 100644
--- a/script-beta/core/diagnostics/undefined-env-child.lua
+++ b/script-beta/core/diagnostics/undefined-env-child.lua
@@ -14,9 +14,10 @@ return function (uri, callback)
if source.node.tag == '_ENV' then
return
end
- local setInENV = vm.eachRef(source, function (info)
- if info.mode == 'set' then
- return true
+ local setInENV
+ vm.eachRef(source, function (src)
+ if vm.isSet(src) then
+ setInENV = true
end
end)
if setInENV then
diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua
index ffb64582..4cb9c1ef 100644
--- a/script-beta/core/diagnostics/undefined-global.lua
+++ b/script-beta/core/diagnostics/undefined-global.lua
@@ -4,6 +4,19 @@ local lang = require 'language'
local library = require 'library'
local config = require 'config'
+local function hasSet(sources)
+ if sources.hasSet ~= nil then
+ return sources.hasSet
+ end
+ sources.hasSet = false
+ for i = 1, #sources do
+ if vm.isSet(sources[i]) then
+ sources.hasSet = true
+ end
+ end
+ return sources.hasSet
+end
+
return function (uri, callback)
local ast = files.getAst(uri)
if not ast then
@@ -12,13 +25,13 @@ return function (uri, callback)
local globalCache = {}
- -- 遍历全局变量,检查所有没有 mode['set'] 的全局变量
+ -- 遍历全局变量,检查所有没有 set 模式的全局变量
local globals = vm.getGlobals(ast.ast)
if not globals then
return
end
- for key, infos in pairs(globals) do
- if infos.mode['set'] == true then
+ for key, sources in pairs(globals) do
+ if hasSet(sources) then
goto CONTINUE
end
if globalCache[key] then
@@ -39,7 +52,7 @@ return function (uri, callback)
for i = 1, #uris do
local destAst = files.getAst(uris[i])
local destGlobals = vm.getGlobals(destAst.ast)
- if destGlobals[key] and destGlobals[key].mode['set'] then
+ if destGlobals[key] and hasSet(destGlobals[key]) then
globalCache[key] = true
goto CONTINUE
end
@@ -54,10 +67,10 @@ return function (uri, callback)
elseif customVersion then
message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
end
- for _, info in ipairs(infos) do
+ for _, source in ipairs(sources) do
callback {
- start = info.source.start,
- finish = info.source.finish,
+ start = source.start,
+ finish = source.finish,
message = message,
}
end
diff --git a/script-beta/core/diagnostics/unused-function.lua b/script-beta/core/diagnostics/unused-function.lua
index f5a49610..52c7749a 100644
--- a/script-beta/core/diagnostics/unused-function.lua
+++ b/script-beta/core/diagnostics/unused-function.lua
@@ -22,12 +22,12 @@ return function (uri, callback)
return
end
local hasSet
- local hasGet = vm.eachRef(source, function (info)
- if info.mode == 'get' then
- return true
- elseif info.mode == 'set'
- or info.mode == 'declare' then
+ local hasGet
+ vm.eachRef(source, function (src)
+ if vm.isSet(src) then
hasSet = true
+ else
+ hasGet = true
end
end)
if not hasGet and hasSet then