summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-05-13 21:31:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-05-13 21:31:02 +0800
commitd6966ae7915b4c5446c48c7a88793617502fd6c6 (patch)
tree7c44aed3ecf3418388fc5a1a9d9f14789b1ae81d
parent50832a63579ba96587a8bd9bcf408302cea808e0 (diff)
downloadlua-language-server-d6966ae7915b4c5446c48c7a88793617502fd6c6.zip
stash
-rw-r--r--script/core/generic.lua7
-rw-r--r--script/core/linker.lua24
-rw-r--r--script/parser/guide.lua2
-rw-r--r--test/definition/luadoc.lua36
4 files changed, 62 insertions, 7 deletions
diff --git a/script/core/generic.lua b/script/core/generic.lua
index 97f3d635..214a8938 100644
--- a/script/core/generic.lua
+++ b/script/core/generic.lua
@@ -91,7 +91,6 @@ local function createValue(closure, proto, callback, road)
value.args = args
value.returns = returns
value.isGeneric = true
- linker.compileLink(value)
linker.pushSource(value)
return value
end
@@ -108,21 +107,23 @@ local function createValue(closure, proto, callback, road)
end
local value = instantValue(closure, proto)
value.node = node
- linker.compileLink(value)
return value
end
if proto.type == 'doc.type.table' then
+ road[#road+1] = linker.SPLIT_CHAR .. linker.TABLE_KEY_CHAR
local tkey = createValue(closure, proto.tkey, callback, road)
+ road[#road] = nil
+
road[#road+1] = linker.SPLIT_CHAR
local tvalue = createValue(closure, proto.tvalue, callback, road)
road[#road] = nil
+
if not tkey and not tvalue then
return nil
end
local value = instantValue(closure, proto)
value.tkey = tkey or proto.tkey
value.tvalue = tvalue or proto.tvalue
- linker.compileLink(value)
return value
end
end
diff --git a/script/core/linker.lua b/script/core/linker.lua
index e57cbaa0..079c2aa4 100644
--- a/script/core/linker.lua
+++ b/script/core/linker.lua
@@ -8,7 +8,8 @@ local SPLIT_CHAR = '\x1F'
local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$'
local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*'
local RETURN_INDEX_CHAR = '#'
-local PARAM_INDEX_CHAR = '@'
+local PARAM_INDEX_CHAR = '@'
+local TABLE_KEY_CHAR = '<'
---创建source的链接信息
---@param id string
@@ -337,9 +338,10 @@ end
local m = {}
-m.SPLIT_CHAR = SPLIT_CHAR
+m.SPLIT_CHAR = SPLIT_CHAR
m.RETURN_INDEX_CHAR = RETURN_INDEX_CHAR
-m.PARAM_INDEX_CHAR = PARAM_INDEX_CHAR
+m.PARAM_INDEX_CHAR = PARAM_INDEX_CHAR
+m.TABLE_KEY_CHAR = TABLE_KEY_CHAR
---添加关联单元
---@param source parser.guide.object
@@ -539,6 +541,14 @@ function m.compileLink(source)
end
end
if source.type == 'doc.type.table' then
+ if source.tkey then
+ local keyID = ('%s%s%s'):format(
+ id,
+ SPLIT_CHAR,
+ TABLE_KEY_CHAR
+ )
+ pushForward(keyID, getID(source.tkey))
+ end
if source.tvalue then
local valueID = ('%s%s'):format(
id,
@@ -664,6 +674,14 @@ function m.compileLink(source)
pushForward(nodeID, getID(source.node))
end
if proto.type == 'doc.type.table' then
+ if source.tkey then
+ local keyID = ('%s%s%s'):format(
+ id,
+ SPLIT_CHAR,
+ TABLE_KEY_CHAR
+ )
+ pushForward(keyID, getID(source.tkey))
+ end
if source.tvalue then
local valueID = ('%s%s'):format(
id,
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 5f56be44..7fc5e3b8 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -74,7 +74,7 @@ m.childMap = {
['doc.generic.object'] = {'generic', 'extends', 'comment'},
['doc.vararg'] = {'vararg', 'comment'},
['doc.type.array'] = {'node'},
- ['doc.type.table'] = {'node', 'tkey', 'tvalue', 'comment'},
+ ['doc.type.table'] = {'tkey', 'tvalue', 'comment'},
['doc.type.function'] = {'#args', '#returns', 'comment'},
['doc.type.literal'] = {'node'},
['doc.type.arg'] = {'extends'},
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 86366752..2b9ec464 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -427,6 +427,21 @@ local <?<!c!>?> = f(b)
]]
TEST [[
+---@generic K
+---@param x table<K, number>
+---@return K
+local function f(x) end
+
+---@class A
+local <!a!>
+
+---@type table<A, number>
+local b
+
+local <?<!c!>?> = f(b)
+]]
+
+TEST [[
---@generic V
---@return fun(t: V[]):V
local function f() end
@@ -557,6 +572,27 @@ TEST [[
local Foo = {}
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)
+end
+]]
+
+TEST [[
+---@class Foo
+local Foo = {}
+function Foo:<!bar1!>() end
+
---@generic T: table, V
---@param t T
---@return fun(table: V[], i?: integer):integer, V