summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/linker.lua32
-rw-r--r--script/core/searcher.lua13
-rw-r--r--test/definition/luadoc.lua24
3 files changed, 57 insertions, 12 deletions
diff --git a/script/core/linker.lua b/script/core/linker.lua
index 97ff4927..f0e30e63 100644
--- a/script/core/linker.lua
+++ b/script/core/linker.lua
@@ -4,7 +4,7 @@ local guide = require 'parser.guide'
local Linkers
local LastIDCache = {}
local SPLIT_CHAR = '\x1F'
-local SPLIT_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']+$'
+local SPLIT_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$'
local RETURN_INDEX_CHAR = '#'
local PARAM_INDEX_CHAR = '@'
@@ -130,6 +130,7 @@ local function getKey(source)
or source.type == 'doc.param'
or source.type == 'doc.vararg'
or source.type == 'doc.field.name'
+ or source.type == 'doc.type.table'
or source.type == 'doc.type.function' then
return source.start, nil
elseif source.type == 'doc.see.field' then
@@ -176,7 +177,10 @@ local function checkMode(source)
return 'da:'
end
if source.type == 'doc.type.function' then
- return 'df:'
+ return 'dfun:'
+ end
+ if source.type == 'doc.type.table' then
+ return 'dtbl:'
end
if source.type == 'doc.vararg' then
return 'dv:'
@@ -440,6 +444,28 @@ local function compileLink(source)
--pushBackward(indexID, callID)
end
end
+ if source.type == 'doc.type.function' then
+ if source.returns then
+ for index, rtn in ipairs(source.returns) do
+ local returnID = ('%s%s%s%s'):format(
+ id,
+ SPLIT_CHAR,
+ RETURN_INDEX_CHAR,
+ index
+ )
+ pushForward(returnID, getID(rtn))
+ end
+ end
+ end
+ if source.type == 'doc.type.table' then
+ if source.value then
+ local valueID = ('%s%s'):format(
+ id,
+ SPLIT_CHAR
+ )
+ pushForward(valueID, getID(source.value))
+ end
+ end
-- 将函数的返回值映射到具体的返回值上
if source.type == 'function' then
-- 检查实体返回值
@@ -455,7 +481,7 @@ local function compileLink(source)
end
for index, rtnObjs in ipairs(returns) do
local returnID = ('%s%s%s%s'):format(
- getID(source),
+ id,
SPLIT_CHAR,
RETURN_INDEX_CHAR,
index
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index abfcf059..30d2e33a 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -176,20 +176,17 @@ function m.searchRefsByID(status, uri, expect, mode)
local index = 0
local function search(id, field, callinfo)
- local fullID
+ local fieldLen
if field then
- fullID = id .. MARK_CHAR .. field
local _, len = field:gsub(linker.SPLIT_CHAR, '')
- if len >= 10 then
- return
- end
+ fieldLen = len
else
- fullID = id
+ fieldLen = 0
end
- if mark[fullID] then
+ if mark[id] and mark[id] <= fieldLen then
return
end
- mark[fullID] = true
+ mark[id] = fieldLen
index = index + 1
queueIDs[index] = id
queueFields[index] = field
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 438425f3..61f203f5 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -321,13 +321,27 @@ print(v1[1].<?bar1?>)
--]]
TEST [[
+---@type fun():<!fun()!>
+local f
+
+local <?<!f2!>?> = f()
+]]
+
+TEST [[
---@class Foo
local Foo = {}
function Foo:<!bar1!>() end
---@type table<number, Foo>
local v1
-local ipairs = ipairs
+
+---@generic T: table, V
+---@param t T
+---@return fun(table: V[], i?: integer):integer, V
+---@return T
+---@return integer i
+local function ipairs(t) end
+
for i, v in ipairs(v1) do
print(v.<?bar1?>)
end
@@ -340,6 +354,14 @@ function Foo:<!bar1!>() end
---@type table<Foo, Foo>
local v1
+
+---@generic T: table, K, V
+---@param t T
+---@return fun(table: table<K, V>, index: K):K, V
+---@return T
+---@return nil
+local function pairs(t) end
+
for k, v in pairs(v1) do
print(k.<?bar1?>)
print(v.bar1)