diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-14 16:09:38 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-14 16:09:38 +0800 |
commit | b5a351cd77cb6f7ddde692557cf0c5049d5ffbac (patch) | |
tree | f633e19250fae4b7ccea8265cba029d435420eef /server/src | |
parent | fe3930a9f692c07eede7de3cb341ea0749b2e2ba (diff) | |
download | lua-language-server-b5a351cd77cb6f7ddde692557cf0c5049d5ffbac.zip |
检查未使用的不定参数
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/constant/DiagnosticDefaultSeverity.lua | 1 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 22 | ||||
-rw-r--r-- | server/src/vm/function.lua | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/server/src/constant/DiagnosticDefaultSeverity.lua b/server/src/constant/DiagnosticDefaultSeverity.lua index bc685cf2..2088a922 100644 --- a/server/src/constant/DiagnosticDefaultSeverity.lua +++ b/server/src/constant/DiagnosticDefaultSeverity.lua @@ -2,6 +2,7 @@ return { ['unused-local'] = 'Hint', ['undefined-global'] = 'Warning', ['unused-label'] = 'Hint', + ['unused-vararg'] = 'Hint', ['trailing-space'] = 'Hint', ['redefined-local'] = 'Hint', ['newline-call'] = 'Information', diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index dcd1a10b..16132bee 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -92,6 +92,22 @@ function mt:searchUnusedLabel(callback) end) end +function mt:searchUnusedVararg(callback) + self.vm:eachSource(function (source) + local value = source:bindFunction() + if not value then + return + end + local func = value:getFunction() + if not func then + return + end + if func._dotsSource and not func._dotsLoad then + callback(func._dotsSource.start, func._dotsSource.finish) + end + end) +end + local function isContainPos(obj, start, finish) if obj.start <= start and obj.finish >= finish then return true @@ -663,6 +679,12 @@ return function (vm, lines, uri) message = lang.script('DIAG_UNUSED_LABEL', key) } end) + -- 未使用的不定参数 + session:doDiagnostics(session.searchUnusedVararg, 'unused-vararg', function () + return { + message = lang.script.DIAG_UNUSED_VARARG + } + end) -- 只有空格与制表符的行,以及后置空格 session:doDiagnostics(session.searchSpaces, 'trailing-space', function (message) return { diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 1ba49f9c..9b236c55 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -210,6 +210,7 @@ function mt:loadDots() if not self._dots then self._dots = createMulti() end + self._dotsLoad = true return self._dots end @@ -373,6 +374,7 @@ function mt:createArg(vm, arg) self:addArg(arg[1], arg, value) elseif arg.type == '...' then self._dots = createMulti() + self._dotsSource = arg end end |