summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/missing-return.lua15
-rw-r--r--script/core/diagnostics/unused-local.lua17
-rw-r--r--script/vm/function.lua14
3 files changed, 20 insertions, 26 deletions
diff --git a/script/core/diagnostics/missing-return.lua b/script/core/diagnostics/missing-return.lua
index d90311d7..42ccaa9f 100644
--- a/script/core/diagnostics/missing-return.lua
+++ b/script/core/diagnostics/missing-return.lua
@@ -39,17 +39,6 @@ local function hasReturn(block)
end
---@param func parser.object
----@return boolean
-local function isEmptyFunction(func)
- if #func > 0 then
- return false
- end
- local startRow = guide.rowColOf(func.start)
- local finishRow = guide.rowColOf(func.finish)
- return finishRow - startRow <= 1
-end
-
----@param func parser.object
---@return integer
local function getReturnsMin(func)
local min = vm.countReturnsOfFunction(func, true)
@@ -77,10 +66,12 @@ return function (uri, callback)
return
end
+ local isMeta = vm.isMetaFile(uri)
+
---@async
guide.eachSourceType(state.ast, 'function', function (source)
-- check declare only
- if isEmptyFunction(source) then
+ if isMeta and vm.isEmptyFunction(source) then
return
end
await.delay()
diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua
index 8f2ee217..52622eb2 100644
--- a/script/core/diagnostics/unused-local.lua
+++ b/script/core/diagnostics/unused-local.lua
@@ -65,24 +65,13 @@ local function isDocClass(source)
return false
end
----@param func parser.object
----@return boolean
-local function isEmptyFunction(func)
- if #func > 0 then
- return false
- end
- local startRow = guide.rowColOf(func.start)
- local finishRow = guide.rowColOf(func.finish)
- return finishRow - startRow <= 1
-end
-
---@param source parser.object
local function isDeclareFunctionParam(source)
if source.parent.type ~= 'funcargs' then
return false
end
local func = source.parent.parent
- return isEmptyFunction(func)
+ return vm.isEmptyFunction(func)
end
return function (uri, callback)
@@ -90,6 +79,8 @@ return function (uri, callback)
if not ast then
return
end
+
+ local isMeta = vm.isMetaFile(uri)
local ignorePatterns = config.get(uri, 'Lua.diagnostics.unusedLocalExclude')
local ignore = glob.glob(ignorePatterns)
guide.eachSourceType(ast.ast, 'local', function (source)
@@ -107,7 +98,7 @@ return function (uri, callback)
if isDocClass(source) then
return
end
- if isDeclareFunctionParam(source) then
+ if isMeta and isDeclareFunctionParam(source) then
return
end
local data = hasGet(source)
diff --git a/script/vm/function.lua b/script/vm/function.lua
index 8b996721..5ad12acf 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -1,5 +1,6 @@
---@class vm
-local vm = require 'vm.vm'
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
---@param arg parser.object
---@return parser.object?
@@ -266,3 +267,14 @@ function vm.isVarargFunctionWithOverloads(func)
end
return false
end
+
+---@param func parser.object
+---@return boolean
+function vm.isEmptyFunction(func)
+ if #func > 0 then
+ return false
+ end
+ local startRow = guide.rowColOf(func.start)
+ local finishRow = guide.rowColOf(func.finish)
+ return finishRow - startRow <= 1
+end