From 0b708180509007bfb6c54d8112f85d5f85ec9210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 26 Oct 2020 20:01:34 +0800 Subject: =?UTF-8?q?array=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/parser/guide.lua | 25 ++++++++++++++++ test-beta/hover/init.lua | 70 ++++++++++++++++++++------------------------ 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 0decb789..4c18a695 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2661,6 +2661,30 @@ function m.inferCheckUpDoc(status, source) end end +function m.inferCheckFieldDoc(status, source) + -- 检查 string[] 的情况 + if source.type == 'getindex' then + local node = source.node + if not node then + return + end + local newStatus = m.status(status) + m.searchInfer(newStatus, node) + local ok + for _, infer in ipairs(newStatus.results) do + local src = infer.source + if src.array then + ok = true + status.results[#status.results+1] = { + type = infer.type:gsub('%[%]$', ''), + source = source, + } + end + end + return ok + end +end + function m.inferCheckUnary(status, source) if source.type ~= 'unary' then return @@ -3400,6 +3424,7 @@ function m.searchInfer(status, obj) local checked = m.inferCheckDoc(status, obj) or m.inferCheckUpDoc(status, obj) + or m.inferCheckFieldDoc(status, obj) or m.inferCheckLibrary(status, obj) or m.inferCheckLiteral(status, obj) or m.inferCheckUnary(status, obj) diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index c4f6cb92..8845c414 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -1041,25 +1041,20 @@ f(1, 2, 3) local t: Class[] ]] -do return end TEST [[ ---@type string[] local ]] [[ -local x: { - [*integer]: string, -} +local x: string[] ]] TEST [[ ----@type (string|boolean)[] +---@type string[]|boolean local ]] [[ -local x: { - [*integer]: string|boolean, -} +local x: boolean|string[] ]] TEST [[ @@ -1071,44 +1066,43 @@ local = t[1] local x: string ]] -TEST [[ ----@type string[] -local t -for _, in ipairs(t) do -end -]] -[[ -local x: string -]] +-- TODO +--TEST [[ +-----@type string[] +--local t +--for _, in ipairs(t) do +--end +--]] +--[[ +--local x: string +--]] -TEST [[ ----@type string[] -local t -for _, in pairs(t) do -end -]] -[[ -local x: string -]] +--TEST [[ +-----@type string[] +--local t +--for _, in pairs(t) do +--end +--]] +--[[ +--local x: string +--]] -TEST [[ ----@type string[] -local t -for , v in pairs(t) do -end -]] -[[ -local k: integer -]] +--TEST [[ +-----@type string[] +--local t +--for , v in pairs(t) do +--end +--]] +--[[ +--local k: integer +--]] TEST [[ ---@type table local ]] [[ -local x: { - [*ClassA]: ClassB, -} +local x: table ]] TEST [[ -- cgit v1.2.3