summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-04 20:30:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-04 20:30:17 +0800
commita927549a7a32d173eb686022f3cf1bfad9815f16 (patch)
tree7f61d2094d777c60eb6f408c01a82a92cb1c72a7 /script
parente006a5a6c0cd566650836ceccbf98d4215449bce (diff)
downloadlua-language-server-a927549a7a32d173eb686022f3cf1bfad9815f16.zip
`unused-function` checks recursive
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/unused-function.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua
index e6ae9386..41c239f9 100644
--- a/script/core/diagnostics/unused-function.lua
+++ b/script/core/diagnostics/unused-function.lua
@@ -23,25 +23,33 @@ return function (uri, callback)
if not ast then
return
end
- -- 只检查局部函数
- guide.eachSourceType(ast.ast, 'function', function (source)
+
+ local cache = {}
+ local function checkFunction(source)
+ if cache[source] ~= nil then
+ return cache[source]
+ end
+ cache[source] = false
local parent = source.parent
if not parent then
- return
+ return false
end
if parent.type ~= 'local'
and parent.type ~= 'setlocal' then
- return
+ return false
end
if isToBeClosed(parent) then
- return
+ return false
end
local hasGet
local refs = vm.getRefs(source)
for _, src in ipairs(refs) do
if vm.isGet(src) then
- hasGet = true
- break
+ local func = guide.getParentFunction(src)
+ if not checkFunction(func) then
+ hasGet = true
+ break
+ end
end
end
if not hasGet then
@@ -60,6 +68,14 @@ return function (uri, callback)
message = lang.script.DIAG_UNUSED_FUNCTION,
}
end
+ cache[source] = true
+ return true
end
+ return false
+ end
+
+ -- 只检查局部函数
+ guide.eachSourceType(ast.ast, 'function', function (source)
+ checkFunction(source)
end)
end