diff options
Diffstat (limited to 'server-beta/src/core')
-rw-r--r-- | server-beta/src/core/diagnostics/redundant-parameter.lua | 25 | ||||
-rw-r--r-- | server-beta/src/core/diagnostics/unused-local.lua | 10 | ||||
-rw-r--r-- | server-beta/src/core/diagnostics/unused-vararg.lua | 32 |
3 files changed, 60 insertions, 7 deletions
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua index c087197c..79c259d8 100644 --- a/server-beta/src/core/diagnostics/redundant-parameter.lua +++ b/server-beta/src/core/diagnostics/redundant-parameter.lua @@ -3,12 +3,28 @@ local guide = require 'parser.guide' local searcher = require 'searcher' local lang = require 'language' local define = require 'proto.define' +local library = require 'library' -local function packCallArgs(source) - if not source.args then +local function packLibraryArgs(source) + local func = searcher.getLibrary(source) + if not func then return nil end local result = {} + if not func.args then + return result + end + for _, lib in ipairs(func.args) do + result[#result+1] = lib + end + return result +end + +local function packCallArgs(source) + local result = {} + if not source.args then + return result + end if source.node and source.node.type == 'getmethod' then result[#result+1] = source.node.node end @@ -19,10 +35,10 @@ local function packCallArgs(source) end local function packFuncArgs(source) + local result = {} if not source.args then - return nil + return result end - local result = {} if source.parent and source.parent.type == 'setmethod' then result[#result+1] = source.parent.node end @@ -58,6 +74,7 @@ return function (uri, callback) end end) + funcArgs = funcArgs or packLibraryArgs(func) if not funcArgs then return end diff --git a/server-beta/src/core/diagnostics/unused-local.lua b/server-beta/src/core/diagnostics/unused-local.lua index e6052e39..22b2e16b 100644 --- a/server-beta/src/core/diagnostics/unused-local.lua +++ b/server-beta/src/core/diagnostics/unused-local.lua @@ -9,7 +9,15 @@ local function hasGet(loc) end for _, ref in ipairs(loc.ref) do if ref.type == 'getlocal' then - return true + if not ref.next then + return true + end + local nextType = ref.next.type + if nextType ~= 'setmethod' + and nextType ~= 'setfield' + and nextType ~= 'setindex' then + return true + end end end return false diff --git a/server-beta/src/core/diagnostics/unused-vararg.lua b/server-beta/src/core/diagnostics/unused-vararg.lua index b3d19c21..74cc08e7 100644 --- a/server-beta/src/core/diagnostics/unused-vararg.lua +++ b/server-beta/src/core/diagnostics/unused-vararg.lua @@ -1,3 +1,31 @@ -return function () - +local files = require 'files' +local guide = require 'parser.guide' +local define = require 'proto.define' +local lang = require 'language' + +return function (uri, callback) + local ast = files.getAst(uri) + if not ast then + return + end + + guide.eachSourceType(ast.ast, 'function', function (source) + local args = source.args + if not args then + return + end + + for _, arg in ipairs(args) do + if arg.type == '...' then + if not arg.ref then + callback { + start = arg.start, + finish = arg.finish, + tags = { define.DiagnosticTag.Unnecessary }, + message = lang.script.DIAG_UNUSED_VARARG, + } + end + end + end + end) end |