From 743d1a3ea8aa964d8aabf13e597fef21bfb361ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 6 Dec 2018 13:52:11 +0800 Subject: =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A3=80=E6=9F=A5=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E5=B1=80=E9=83=A8=E5=8F=98=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=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 --- server/src/matcher/compile.lua | 2 +- server/src/matcher/diagnostics.lua | 82 ++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 44 deletions(-) (limited to 'server/src/matcher') diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua index 68fdf9b6..02db109c 100644 --- a/server/src/matcher/compile.lua +++ b/server/src/matcher/compile.lua @@ -227,7 +227,7 @@ function mt:searchReturn(action) end end -function mt:setTable(var, tbl, mode) +function mt:setTable(var, tbl) if not var or not tbl then return end diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua index 9cd4f6ee..ffdab80e 100644 --- a/server/src/matcher/diagnostics.lua +++ b/server/src/matcher/diagnostics.lua @@ -1,49 +1,45 @@ -local DiagnosticSeverity = { - Error = 1, - Warning = 2, - Information = 3, - Hint = 4, -} - --[[ -/** - * Represents a related message and source code location for a diagnostic. This should be - * used to point to code locations that cause or related to a diagnostics, e.g when duplicating - * a symbol in a scope. - */ -export interface DiagnosticRelatedInformation { - /** - * The location of this related diagnostic information. - */ - location: Location; - - /** - * The message of this related diagnostic information. - */ - message: string; +data = { + start = 1, + finish = 1, + level = 'Error' or 'Warning' or 'Information' or 'Hint', + code = '', + message = '', } ]]-- -return function (ast, results) - local diagnostics = {} - - diagnostics[1] = { - range = { - start = { - line = 0, - character = 0, - }, - ['end'] = { - line = 0, - character = 10, - }, - }, - severity = DiagnosticSeverity.Warning, - code = 'I am code', - source = 'I am source', - message = 'I am message', - relatedInformation = nil, - } +local function searchUnusedLocals(results, callback) + for _, var in ipairs(results.vars) do + if var.type ~= 'local' then + goto NEXT_VAR + end + if var.key == 'self' + or var.key == '_' + or var.key == '_ENV' + then + goto NEXT_VAR + end + for _, info in ipairs(var) do + if info.type == 'get' then + goto NEXT_VAR + end + end + callback(var.source.start, var.source.finish, var.key) + ::NEXT_VAR:: + end +end - return diagnostics +return function (ast, results, lines) + local datas = {} + -- 搜索未使用的局部变量 + searchUnusedLocals(results, function (start, finish, code) + datas[#datas+1] = { + start = start, + finish = finish, + level = 'Warning', + code = code, + message = 'Unused local', -- LOCALE + } + end) + return datas end -- cgit v1.2.3