summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-17 16:57:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-17 16:57:36 +0800
commit505f8de67ce7759e6321017abbd69f1d4799e8b1 (patch)
tree381159859043ef9bc6b05dda9a5e0749ba0bb8b7 /script/core/diagnostics
parent6c89b0a55de7e47c9300b4f42421d8f45433da4c (diff)
downloadlua-language-server-505f8de67ce7759e6321017abbd69f1d4799e8b1.zip
don't check `duplicate-set-field` in different if
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/duplicate-set-field.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua
index 9d6f10ce..a4b205dd 100644
--- a/script/core/diagnostics/duplicate-set-field.lua
+++ b/script/core/diagnostics/duplicate-set-field.lua
@@ -11,6 +11,22 @@ local sourceTypes = {
'setindex',
}
+---@param source parser.object
+---@return parser.object?
+local function getTopFunctionOfIf(source)
+ while true do
+ if source.type == 'ifblock'
+ or source.type == 'elseifblock'
+ or source.type == 'elseblock'
+ or source.type == 'function'
+ or source.type == 'main' then
+ return source
+ end
+ source = source.parent
+ end
+ return nil
+end
+
---@async
return function (uri, callback)
local state = files.getState(uri)
@@ -18,6 +34,10 @@ return function (uri, callback)
return
end
+ if vm.isMetaFile(uri) then
+ return
+ end
+
---@async
guide.eachSourceTypes(state.ast, sourceTypes, function (src)
await.delay()
@@ -29,6 +49,7 @@ return function (uri, callback)
if not value or value.type ~= 'function' then
return
end
+ local myTopBlock = getTopFunctionOfIf(src)
local defs = vm.getDefs(src)
for _, def in ipairs(defs) do
if def == src then
@@ -39,6 +60,10 @@ return function (uri, callback)
and def.type ~= 'setindex' then
goto CONTINUE
end
+ local defTopBlock = getTopFunctionOfIf(def)
+ if uri == guide.getUri(def) and myTopBlock ~= defTopBlock then
+ goto CONTINUE
+ end
local defValue = vm.getObjectValue(def)
if not defValue or defValue.type ~= 'function' then
goto CONTINUE