diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/missing-parameter.lua | 20 | ||||
-rw-r--r-- | script/core/diagnostics/missing-return-value.lua | 23 | ||||
-rw-r--r-- | script/core/diagnostics/missing-return.lua | 26 | ||||
-rw-r--r-- | script/core/diagnostics/redundant-parameter.lua | 18 | ||||
-rw-r--r-- | script/core/diagnostics/redundant-return-value.lua | 23 | ||||
-rw-r--r-- | script/core/diagnostics/return-type-mismatch.lua | 25 |
6 files changed, 58 insertions, 77 deletions
diff --git a/script/core/diagnostics/missing-parameter.lua b/script/core/diagnostics/missing-parameter.lua index 78b94a09..1194f6d1 100644 --- a/script/core/diagnostics/missing-parameter.lua +++ b/script/core/diagnostics/missing-parameter.lua @@ -29,4 +29,24 @@ return function (uri, callback) message = lang.script('DIAG_MISS_ARGS', funcArgs, callArgs), } end) + + ---@async + guide.eachSourceType(state.ast, 'function', function (source) + await.delay() + if not source.args then + return + end + local funcArgs = vm.countParamsOfSource(source) + if funcArgs == 0 then + return + end + local myArgs = #source.args + if myArgs < funcArgs then + callback { + start = source.args.start, + finish = source.args.finish, + message = lang.script('DIAG_MISS_ARGS', funcArgs, myArgs), + } + end + end) end diff --git a/script/core/diagnostics/missing-return-value.lua b/script/core/diagnostics/missing-return-value.lua index 9eab7074..5c672b54 100644 --- a/script/core/diagnostics/missing-return-value.lua +++ b/script/core/diagnostics/missing-return-value.lua @@ -4,27 +4,6 @@ local vm = require 'vm' local lang = require 'language' local await = require 'await' ----@param func parser.object ----@return integer -local function getReturnsMin(func) - local min = vm.countReturnsOfFunction(func, true) - if min == 0 then - return 0 - end - for _, doc in ipairs(func.bindDocs) do - if doc.type == 'doc.overload' then - local n = vm.countReturnsOfFunction(doc.overload) - if n == 0 then - return 0 - end - if n < min then - min = n - end - end - end - return min -end - ---@async return function (uri, callback) local state = files.getState(uri) @@ -39,7 +18,7 @@ return function (uri, callback) if not returns then return end - local min = getReturnsMin(source) + local min = vm.countReturnsOfSource(source) if min == 0 then return end diff --git a/script/core/diagnostics/missing-return.lua b/script/core/diagnostics/missing-return.lua index 42ccaa9f..7333e5e3 100644 --- a/script/core/diagnostics/missing-return.lua +++ b/script/core/diagnostics/missing-return.lua @@ -38,27 +38,6 @@ local function hasReturn(block) return false end ----@param func parser.object ----@return integer -local function getReturnsMin(func) - local min = vm.countReturnsOfFunction(func, true) - if min == 0 then - return 0 - end - for _, doc in ipairs(func.bindDocs) do - if doc.type == 'doc.overload' then - local n = vm.countReturnsOfFunction(doc.overload) - if n == 0 then - return 0 - end - if n < min then - min = n - end - end - end - return min -end - ---@async return function (uri, callback) local state = files.getState(uri) @@ -75,7 +54,7 @@ return function (uri, callback) return end await.delay() - if getReturnsMin(source) == 0 then + if vm.countReturnsOfSource(source) == 0 then return end if hasReturn(source) then @@ -86,8 +65,7 @@ return function (uri, callback) if lastAction then pos = lastAction.range or lastAction.finish else - local row = guide.rowColOf(source.finish) - pos = guide.positionOf(row - 1, 0) + pos = source.keyword[3] or source.finish end callback { start = pos, diff --git a/script/core/diagnostics/redundant-parameter.lua b/script/core/diagnostics/redundant-parameter.lua index 9898d9bd..667f9c61 100644 --- a/script/core/diagnostics/redundant-parameter.lua +++ b/script/core/diagnostics/redundant-parameter.lua @@ -52,4 +52,22 @@ return function (uri, callback) end end end) + + ---@async + guide.eachSourceType(state.ast, 'function', function (source) + await.delay() + if not source.args then + return + end + local _, funcArgs = vm.countParamsOfSource(source) + local myArgs = #source.args + for i = funcArgs + 1, myArgs do + local arg = source.args[i] + callback { + start = arg.start, + finish = arg.finish, + message = lang.script('DIAG_OVER_MAX_ARGS', funcArgs, myArgs), + } + end + end) end diff --git a/script/core/diagnostics/redundant-return-value.lua b/script/core/diagnostics/redundant-return-value.lua index 9b913438..18667840 100644 --- a/script/core/diagnostics/redundant-return-value.lua +++ b/script/core/diagnostics/redundant-return-value.lua @@ -4,27 +4,6 @@ local vm = require 'vm' local lang = require 'language' local await = require 'await' ----@param func parser.object ----@return number -local function getReturnsMax(func) - local _, max = vm.countReturnsOfFunction(func, true) - if max == math.huge then - return max - end - for _, doc in ipairs(func.bindDocs) do - if doc.type == 'doc.overload' then - local _, n = vm.countReturnsOfFunction(doc.overload) - if n == math.huge then - return n - end - if n > max then - max = n - end - end - end - return max -end - ---@async return function (uri, callback) local state = files.getState(uri) @@ -39,7 +18,7 @@ return function (uri, callback) return end await.delay() - local max = getReturnsMax(source) + local _, max = vm.countReturnsOfSource(source) for _, ret in ipairs(returns) do local rmin, rmax = vm.countList(ret) if rmin > max then diff --git a/script/core/diagnostics/return-type-mismatch.lua b/script/core/diagnostics/return-type-mismatch.lua index 2ff8a909..1f335e9d 100644 --- a/script/core/diagnostics/return-type-mismatch.lua +++ b/script/core/diagnostics/return-type-mismatch.lua @@ -8,21 +8,28 @@ local util = require 'utility' ---@param func parser.object ---@return vm.node[]? local function getDocReturns(func) - if not func.bindDocs then - return nil - end ---@type table<integer, vm.node> local returns = util.defaultTable(function () return vm.createNode() end) - for _, doc in ipairs(func.bindDocs) do - if doc.type == 'doc.return' then - for _, ret in ipairs(doc.returns) do - returns[ret.returnIndex]:merge(vm.compileNode(ret)) + if func.bindDocs then + for _, doc in ipairs(func.bindDocs) do + if doc.type == 'doc.return' then + for _, ret in ipairs(doc.returns) do + returns[ret.returnIndex]:merge(vm.compileNode(ret)) + end + end + if doc.type == 'doc.overload' then + for i, ret in ipairs(doc.overload.returns) do + returns[i]:merge(vm.compileNode(ret)) + end end end - if doc.type == 'doc.overload' then - for i, ret in ipairs(doc.overload.returns) do + end + for nd in vm.compileNode(func):eachObject() do + if nd.type == 'doc.type.function' then + ---@cast nd parser.object + for i, ret in ipairs(nd.returns) do returns[i]:merge(vm.compileNode(ret)) end end |