summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/parser/guide.lua3
-rw-r--r--script-beta/parser/luadoc.lua22
-rw-r--r--test-beta/hover/init.lua14
3 files changed, 38 insertions, 1 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index f4bf65f2..90566865 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -2483,6 +2483,9 @@ local function getDocTypeUnitName(unit)
elseif unit.type == 'doc.type.function' then
typeName = 'function'
end
+ if unit.typeGeneric then
+ typeName = ('<%s>'):format(typeName)
+ end
if unit.array then
typeName = typeName .. '[]'
elseif unit.generic then
diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua
index c55484cf..68fef250 100644
--- a/script-beta/parser/luadoc.lua
+++ b/script-beta/parser/luadoc.lua
@@ -678,6 +678,27 @@ local function isNextLine(lns, binded, doc)
return newRow - lastRow == 1
end
+local function bindGeneric(binded)
+ local generics = {}
+ for _, doc in ipairs(binded) do
+ if doc.type == 'doc.generic' then
+ for _, obj in ipairs(doc.generics) do
+ local name = obj.generic[1]
+ generics[name] = {}
+ end
+ elseif doc.type == 'doc.param'
+ or doc.type == 'doc.return' then
+ guide.eachSourceType(doc, 'doc.type.name', function (src)
+ local name = src[1]
+ if generics[name] then
+ generics[name][#generics[name]+1] = src
+ src.typeGeneric = generics
+ end
+ end)
+ end
+ end
+end
+
local function bindDoc(state, lns, binded)
if not binded then
return
@@ -691,6 +712,7 @@ local function bindDoc(state, lns, binded)
doc.bindGroup = binded
doc.bindSources = bindSources
end
+ bindGeneric(binded)
local row = guide.positionOf(lns, lastDoc.start)
local start, finish = guide.lineRange(lns, row + 1)
if start >= finish then
diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua
index b3b6719d..feb574d4 100644
--- a/test-beta/hover/init.lua
+++ b/test-beta/hover/init.lua
@@ -973,6 +973,18 @@ function f()
2. C
]]
+TEST [[
+---@generic T
+---@param x T
+---@return T
+local function <?f?>(x)
+end
+]]
+[[
+function f(x: <T>)
+ -> <T>
+]]
+
do return end
TEST [[
---@generic T
@@ -984,7 +996,7 @@ end
local <?r?> = f(1)
]]
[[
-local r: number
+local r: integer
]]
TEST [[