From 30a88ee1b1f60e657393a16e55cddae9cb01a62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 5 Nov 2019 21:30:04 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/diagnostics/redundant-value.lua | 13 +++++++++- server-beta/src/parser/guide.lua | 30 ++++++++++++++-------- server-beta/test/diagnostics/init.lua | 7 +++++ 3 files changed, 38 insertions(+), 12 deletions(-) (limited to 'server-beta') diff --git a/server-beta/src/core/diagnostics/redundant-value.lua b/server-beta/src/core/diagnostics/redundant-value.lua index b3d19c21..71749f56 100644 --- a/server-beta/src/core/diagnostics/redundant-value.lua +++ b/server-beta/src/core/diagnostics/redundant-value.lua @@ -1,3 +1,14 @@ -return function () +local files = require 'files' +local guide = require 'parser.guide' + +local function check(source) end + +return function (uri, callback) + local ast = files.getAst(uri) + if not ast then + return + end + +end diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 92dd79bc..952fa3c6 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -309,23 +309,31 @@ end --- 遍历所有指定类型的source function m.eachSourceType(ast, type, callback) - if not ast.typeCache then - ast.typeCache = {} - end - local cache = ast.typeCache[type] + local cache = ast.typeCache if not cache then - cache = {} - ast.typeCache[type] = cache local mark = {} + cache = {} + ast.typeCache = cache m.eachSource(ast, function (source) - if source.type == type and not mark[source] then - mark[source] = true - cache[#cache+1] = source + if mark[source] then + return end + mark[source] = true + local tp = source.type + local myCache = cache[tp] + if not myCache then + myCache = {} + cache[tp] = myCache + end + myCache[#myCache+1] = source end) end - for i = 1, #cache do - callback(cache[i]) + local myCache = cache[type] + if not myCache then + return + end + for i = 1, #myCache do + callback(myCache[i]) end end diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua index d8724375..430ead8d 100644 --- a/server-beta/test/diagnostics/init.lua +++ b/server-beta/test/diagnostics/init.lua @@ -262,6 +262,13 @@ return [[ ]] ]=] +TEST [[ +local t = {} + +return t +]] + config.config.diagnostics.disable['unused-function'] = true TEST [[ local mt, x -- cgit v1.2.3