summaryrefslogtreecommitdiff
path: root/server-beta/src/core/diagnostics/redundant-parameter.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-05 19:31:38 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-05 19:31:38 +0800
commitc844e46ae97f28ec928db6b701fdf5f2eea2664d (patch)
tree938d77a0aadb6a3975d146659302137f58d9babc /server-beta/src/core/diagnostics/redundant-parameter.lua
parent5d4d2ccd06d56bb92219baf3825c5786efdf906c (diff)
downloadlua-language-server-c844e46ae97f28ec928db6b701fdf5f2eea2664d.zip
更新诊断实现
Diffstat (limited to 'server-beta/src/core/diagnostics/redundant-parameter.lua')
-rw-r--r--server-beta/src/core/diagnostics/redundant-parameter.lua81
1 files changed, 79 insertions, 2 deletions
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua
index b3d19c21..c087197c 100644
--- a/server-beta/src/core/diagnostics/redundant-parameter.lua
+++ b/server-beta/src/core/diagnostics/redundant-parameter.lua
@@ -1,3 +1,80 @@
-return function ()
-
+local files = require 'files'
+local guide = require 'parser.guide'
+local searcher = require 'searcher'
+local lang = require 'language'
+local define = require 'proto.define'
+
+local function packCallArgs(source)
+ if not source.args then
+ return nil
+ end
+ local result = {}
+ if source.node and source.node.type == 'getmethod' then
+ result[#result+1] = source.node.node
+ end
+ for _, arg in ipairs(source.args) do
+ result[#result+1] = arg
+ end
+ return result
+end
+
+local function packFuncArgs(source)
+ if not source.args then
+ return nil
+ end
+ local result = {}
+ if source.parent and source.parent.type == 'setmethod' then
+ result[#result+1] = source.parent.node
+ end
+ for _, arg in ipairs(source.args) do
+ result[#result+1] = arg
+ end
+ return result
+end
+
+return function (uri, callback)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+
+ guide.eachSourceType(ast.ast, 'call', function (source)
+ local callArgs = packCallArgs(source)
+ if not callArgs then
+ return
+ end
+
+ local func = source.node
+ local funcArgs
+ searcher.eachRef(func, function (info)
+ if info.mode == 'value' then
+ local src = info.source
+ if src.type == 'function' then
+ local args = packFuncArgs(src)
+ if args and (not funcArgs or #funcArgs < #args) then
+ funcArgs = args
+ end
+ end
+ end
+ end)
+
+ if not funcArgs then
+ return
+ end
+
+ local lastArg = funcArgs[#funcArgs]
+ if lastArg and lastArg.type == '...' then
+ return
+ end
+
+ for i = #funcArgs + 1, #callArgs do
+ local arg = callArgs[i]
+ callback {
+ start = arg.start,
+ finish = arg.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script('DIAG_OVER_MAX_ARGS', #funcArgs, #callArgs)
+ }
+ end
+ end)
end