summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/missing-return-value.lua23
-rw-r--r--script/core/diagnostics/missing-return.lua23
-rw-r--r--script/core/diagnostics/redundant-return-value.lua28
3 files changed, 40 insertions, 34 deletions
diff --git a/script/core/diagnostics/missing-return-value.lua b/script/core/diagnostics/missing-return-value.lua
index 3aa7bd55..9eab7074 100644
--- a/script/core/diagnostics/missing-return-value.lua
+++ b/script/core/diagnostics/missing-return-value.lua
@@ -5,27 +5,9 @@ local lang = require 'language'
local await = require 'await'
---@param func parser.object
-local function hasDocReturn(func)
- if not func.bindDocs then
- return false
- end
- for _, doc in ipairs(func.bindDocs) do
- if doc.type == 'doc.return' then
- return true
- end
- if doc.type == 'doc.overload' then
- if #doc.overload.returns > 0 then
- return true
- end
- end
- end
- return false
-end
-
----@param func parser.object
---@return integer
local function getReturnsMin(func)
- local min = vm.countReturnsOfFunction(func)
+ local min = vm.countReturnsOfFunction(func, true)
if min == 0 then
return 0
end
@@ -57,9 +39,6 @@ return function (uri, callback)
if not returns then
return
end
- if not hasDocReturn(source) then
- return
- end
local min = getReturnsMin(source)
if min == 0 then
return
diff --git a/script/core/diagnostics/missing-return.lua b/script/core/diagnostics/missing-return.lua
index e3539ac0..d90311d7 100644
--- a/script/core/diagnostics/missing-return.lua
+++ b/script/core/diagnostics/missing-return.lua
@@ -49,6 +49,27 @@ local function isEmptyFunction(func)
return finishRow - startRow <= 1
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)
@@ -63,7 +84,7 @@ return function (uri, callback)
return
end
await.delay()
- if vm.countReturnsOfFunction(source, true) == 0 then
+ if getReturnsMin(source) == 0 then
return
end
if hasReturn(source) then
diff --git a/script/core/diagnostics/redundant-return-value.lua b/script/core/diagnostics/redundant-return-value.lua
index 36432f98..9b913438 100644
--- a/script/core/diagnostics/redundant-return-value.lua
+++ b/script/core/diagnostics/redundant-return-value.lua
@@ -4,16 +4,25 @@ local vm = require 'vm'
local lang = require 'language'
local await = require 'await'
-local function hasDocReturn(func)
- if not func.bindDocs then
- return false
+---@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.return' then
- return true
+ 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 false
+ return max
end
---@async
@@ -25,15 +34,12 @@ return function (uri, callback)
---@async
guide.eachSourceType(state.ast, 'function', function (source)
- await.delay()
- if not hasDocReturn(source) then
- return
- end
- local _, max = vm.countReturnsOfFunction(source)
local returns = source.returns
if not returns then
return
end
+ await.delay()
+ local max = getReturnsMax(source)
for _, ret in ipairs(returns) do
local rmin, rmax = vm.countList(ret)
if rmin > max then