summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-07 20:58:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-07 20:58:59 +0800
commit46974b3b740c7f58ecd8094392ab7f4c5c254f44 (patch)
tree97f947d5b63b9fd257db66cc5a868bccaa3909ea
parenta31cb772fa4f1da3fd78e4d9f5a01729c22883f7 (diff)
downloadlua-language-server-46974b3b740c7f58ecd8094392ab7f4c5c254f44.zip
update
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/parser/luadoc.lua1
-rw-r--r--script/vm/compiler.lua7
-rw-r--r--script/vm/generic.lua3
-rw-r--r--script/vm/global-manager.lua8
-rw-r--r--test/definition/luadoc.lua11
6 files changed, 29 insertions, 3 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 1d634cbf..1bda2d32 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -25,7 +25,7 @@ local type = type
---@field field parser.object
---@field method parser.object
---@field index parser.object
----@field extends parser.object[]
+---@field extends parser.object[]|parser.object
---@field types parser.object[]
---@field fields parser.object[]
---@field tkey parser.object
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index fbecbb3e..5b9bdfad 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -768,6 +768,7 @@ local function parseAlias()
return nil
end
result.start = getStart()
+ result.signs = parseSigns(result, 'name')
result.extends = parseType(result)
if not result.extends then
pushWarning {
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 10b79a3c..c870cc0e 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -598,7 +598,12 @@ local function compileByGlobal(source)
end
end
if set.type == 'doc.alias' then
- nodeMgr.setNode(source, m.compileNode(set.extends))
+ if set.extends._generic then
+ local resolved = set.extends._generic:resolve(source.signs)
+ nodeMgr.setNode(source, resolved)
+ else
+ nodeMgr.setNode(source, m.compileNode(set.extends))
+ end
end
end
end
diff --git a/script/vm/generic.lua b/script/vm/generic.lua
index 3aa61231..7b0eb120 100644
--- a/script/vm/generic.lua
+++ b/script/vm/generic.lua
@@ -127,9 +127,10 @@ end
---@param parent vm.node.generic-manager
---@param node vm.node
return function (parent, node)
+ local compiler = require 'vm.compiler'
local generic = setmetatable({
parent = parent,
- node = node,
+ node = compiler.compileNode(node),
}, mt)
return generic
end
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index 130a11db..2ffaf3da 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -165,6 +165,14 @@ local compilerGlobalMap = util.switch()
local alias = m.declareGlobal('type', name, uri)
alias:addSet(uri, source)
source._globalNode = alias
+
+ if source.signs then
+ source._generic = genericMgr(source)
+ for _, sign in ipairs(source.signs) do
+ source._generic:addSign(sign)
+ end
+ source.extends._generic = source._generic:getChild(source.extends)
+ end
end)
: case 'doc.type.name'
: call(function (source)
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 7b6fd0da..0021556f 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -644,6 +644,17 @@ print(t.<?x?>)
]]
TEST [[
+---@alias TT<V> { <!x!>: V }
+
+---@type TT<A>
+local t
+
+---@class A: <!{}!>
+
+print(t.<?x?>)
+]]
+
+TEST [[
---@class Foo
local Foo = {}
function Foo:<!bar1!>() end