diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-15 23:47:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-15 23:47:39 +0800 |
commit | f4fcddfa8805848b7ce7c58188cca711fc429c3b (patch) | |
tree | 8e8b1947a40d274e7237dddab30c195bfb0ad1ae /server-beta/src | |
parent | 2862282e18315a6474001a994e385fee132753a6 (diff) | |
download | lua-language-server-f4fcddfa8805848b7ce7c58188cca711fc429c3b.zip |
诊断:未使用的函数 只检查局部函数与全局函数
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/core/diagnostics/unused-function.lua | 10 | ||||
-rw-r--r-- | server-beta/src/parser/ast.lua | 28 |
2 files changed, 30 insertions, 8 deletions
diff --git a/server-beta/src/core/diagnostics/unused-function.lua b/server-beta/src/core/diagnostics/unused-function.lua index eb6b8f7f..ca3a751d 100644 --- a/server-beta/src/core/diagnostics/unused-function.lua +++ b/server-beta/src/core/diagnostics/unused-function.lua @@ -10,7 +10,17 @@ return function (uri, callback) if not ast then return end + -- 只检查局部函数与全局函数 guide.eachSourceType(ast.ast, 'function', function (source) + local parent = source.parent + if not parent then + return + end + if parent.type ~= 'local' + and parent.type ~= 'setlocal' + and parent.type ~= 'setglobal' then + return + end local hasSet local hasGet = searcher.eachRef(source, function (info) if info.mode == 'get' then diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua index f3fec01b..ded42891 100644 --- a/server-beta/src/parser/ast.lua +++ b/server-beta/src/parser/ast.lua @@ -697,6 +697,7 @@ local Defs = { return lv1 < lv2 end end) + local final for i = #ops, 1, -1 do local n = ops[i] local op = list[n] @@ -710,17 +711,28 @@ local Defs = { [1] = left, [2] = right, } - list[n-1] = exp - list[n+1] = exp - local lastN = ops[i+1] - if lastN then - list[lastN-1] = exp - list[lastN+1] = exp + local leftIndex, rightIndex + if list[left] then + leftIndex = list[left[1]] + else + leftIndex = n - 1 + end + if list[right] then + rightIndex = list[right[2]] + else + rightIndex = n + 1 end + + list[leftIndex] = exp + list[rightIndex] = exp + list[left] = leftIndex + list[right] = rightIndex + list[exp] = n + final = exp + checkOpVersion(op) end - local final = ops[1] - return list[final-1] + return final end, Paren = function (start, exp, finish) if exp and exp.type == 'paren' then |