summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/rename.lua2
-rw-r--r--script/parser/luadoc.lua12
-rw-r--r--script/vm/compiler.lua5
-rw-r--r--script/vm/ref.lua6
-rw-r--r--script/vm/type.lua4
-rw-r--r--test/definition/table.lua10
-rw-r--r--test/diagnostics/common.lua1
-rw-r--r--test/hover/init.lua8
-rw-r--r--test/references/common.lua7
9 files changed, 49 insertions, 6 deletions
diff --git a/script/core/rename.lua b/script/core/rename.lua
index 7599fad6..c3325b7e 100644
--- a/script/core/rename.lua
+++ b/script/core/rename.lua
@@ -183,7 +183,7 @@ local function ofField(source, newname, callback)
local key = guide.getKeyName(source)
local refs = vm.getRefs(source)
for _, ref in ipairs(refs) do
- ofFieldThen(key, ref, newname, callback)
+ ofFieldThen(key, ref, newname, callback)
end
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 061110c8..95e902af 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -1471,17 +1471,26 @@ local function bindDocsBetween(sources, binded, bindSources, start, finish)
end
-- 从前往后进行绑定
+ local skipUntil
for i = index, max do
local src = sources[i]
if src and src.start >= start then
if src.start >= finish then
break
end
+ if skipUntil then
+ if skipUntil > src.start then
+ goto CONTINUE
+ else
+ skipUntil = nil
+ end
+ end
-- 遇到table后中断,处理以下情况:
-- ---@type AAA
-- local t = {x = 1, y = 2}
if src.type == 'table' then
- break
+ skipUntil = skipUntil or src.finish
+ goto CONTINUE
end
if src.start >= start then
if src.type == 'local'
@@ -1498,6 +1507,7 @@ local function bindDocsBetween(sources, binded, bindSources, start, finish)
bindSources[#bindSources+1] = src
end
end
+ ::CONTINUE::
end
end
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index e33ec234..b7e394ae 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1375,7 +1375,10 @@ local compilerSwitch = util.switch()
if not hasMarkDoc then
vm.compileByParentNode(source.parent, guide.getKeyName(source), false, function (src)
- vm.setNode(source, vm.compileNode(src))
+ if src.type == 'doc.field'
+ or src.type == 'doc.type.field' then
+ vm.setNode(source, vm.compileNode(src))
+ end
end)
end
end)
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index c97ca5e6..c8b98acf 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -91,21 +91,21 @@ local function searchField(source, pushResult, defMap, fileNotify)
return
end
---@async
- guide.eachSourceType(state.ast, 'getfield', function (src)
+ guide.eachSourceTypes(state.ast, {'getfield', 'setfield'}, function (src)
if src.field and src.field[1] == key then
checkDef(src)
await.delay()
end
end)
---@async
- guide.eachSourceType(state.ast, 'getmethod', function (src)
+ guide.eachSourceTypes(state.ast, {'getmethod', 'setmethod'}, function (src)
if src.method and src.method[1] == key then
checkDef(src)
await.delay()
end
end)
---@async
- guide.eachSourceType(state.ast, 'getindex', function (src)
+ guide.eachSourceTypes(state.ast, {'getindex', 'setindex'}, function (src)
if src.index and src.index.type == 'string' and src.index[1] == key then
checkDef(src)
await.delay()
diff --git a/script/vm/type.lua b/script/vm/type.lua
index ebea8c30..d2c5d663 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -209,10 +209,14 @@ end
---@return boolean
function vm.canCastType(uri, defNode, refNode)
local defInfer = vm.getInfer(defNode)
+ local refInfer = vm.getInfer(refNode)
if defInfer:hasUnknown(uri) then
return true
end
+ if refInfer:hasUnknown(uri) then
+ return true
+ end
-- allow `local x = {};x = nil`,
-- but not allow `local x ---@type table;x = nil`
diff --git a/test/definition/table.lua b/test/definition/table.lua
index 6dbe627c..ed1ea94d 100644
--- a/test/definition/table.lua
+++ b/test/definition/table.lua
@@ -175,3 +175,13 @@ t.<?x?>
--
--print(t[<?1?>])
--]]
+
+TEST [[
+local t = {
+ <!<?x?>!> = 1,
+}
+
+local y
+
+t.x = y
+]]
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 2b3104d1..0e7d4436 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1811,6 +1811,7 @@ local x = 0
<!x!> = 1.0
]]
+do return end
TEST [[
---@diagnostic disable: unused-local
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 48daf593..0925db77 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1939,3 +1939,11 @@ print(x.<?y?>)
[[
(field) x.y: unknown
]]
+
+TEST [[
+---@async
+x({}, <?function?> () end)
+]]
+[[
+(async) function ()
+]]
diff --git a/test/references/common.lua b/test/references/common.lua
index 47dfb099..c20b32ed 100644
--- a/test/references/common.lua
+++ b/test/references/common.lua
@@ -55,6 +55,13 @@ print(t.<!a!>)
]]
TEST [[
+local t = {
+ <~a~> = 1
+}
+t.<!a!> = 1
+]]
+
+TEST [[
t[<~'a'~>] = 1
print(t.<!a!>)
]]