File tree Expand file tree Collapse file tree 4 files changed +100
-1
lines changed Expand file tree Collapse file tree 4 files changed +100
-1
lines changed Original file line number Diff line number Diff line change @@ -705,6 +705,53 @@ local function parseCode(parent)
705705 return code
706706end
707707
708+ local function parseCodePattern (parent )
709+ local tp , pattern = peekToken ()
710+ if not tp or tp ~= ' name' then
711+ return nil
712+ end
713+ local codeOffset
714+ local finishOffset
715+ local content
716+ for i = 2 , 8 do
717+ local next , nextContent = peekToken (i )
718+ if not next or TokenFinishs [Ci + i - 1 ] + 1 ~= TokenStarts [Ci + i ] then
719+ if codeOffset then
720+ finishOffset = i
721+ break
722+ end
723+ --- 不连续的name,无效的
724+ return nil
725+ end
726+ if next == ' code' then
727+ if codeOffset and content ~= nextContent then
728+ -- 暂时不支持多generic
729+ return nil
730+ end
731+ codeOffset = i
732+ pattern = pattern .. " %s"
733+ content = nextContent
734+ elseif next ~= ' name' then
735+ return nil
736+ else
737+ pattern = pattern .. nextContent
738+ end
739+ end
740+ local start = getStart ()
741+ for i = 2 , finishOffset do
742+ nextToken ()
743+ end
744+ local code = {
745+ type = ' doc.type.code' ,
746+ start = start ,
747+ finish = getFinish (),
748+ parent = parent ,
749+ pattern = pattern ,
750+ [1 ] = content ,
751+ }
752+ return code
753+ end
754+
708755local function parseInteger (parent )
709756 local tp , content = peekToken ()
710757 if not tp or tp ~= ' integer' then
@@ -760,6 +807,7 @@ function parseTypeUnit(parent)
760807 or parseInteger (parent )
761808 or parseBoolean (parent )
762809 or parseParen (parent )
810+ or parseCodePattern (parent )
763811 if not result then
764812 result = parseName (' doc.type.name' , parent )
765813 or parseDots (' doc.type.name' , parent )
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ function mt:resolve(uri, args)
5353 for n in node :eachObject () do
5454 if n .type == ' string' then
5555 --- @cast n parser.object
56- local type = vm .declareGlobal (' type' , n [1 ], guide .getUri (n ))
56+ local type = vm .declareGlobal (' type' , object . pattern and object . pattern : format ( n [ 1 ]) or n [1 ], guide .getUri (n ))
5757 resolved [key ] = vm .createNode (type , resolved [key ])
5858 end
5959 end
Original file line number Diff line number Diff line change @@ -4413,3 +4413,24 @@ new 'A' {
44134413 kind = define .CompletionItemKind .Property ,
44144414 }
44154415}
4416+
4417+ TEST [[
4418+ ---@class namespace.A
4419+ ---@overload fun(x: {id: string})
4420+
4421+ ---@generic T
4422+ ---@param t namespace.`T`
4423+ ---@return T
4424+ local function new(t) end
4425+
4426+ new 'A' {
4427+ <??>
4428+ }
4429+ ]]
4430+ {
4431+ {
4432+ label = ' id' ,
4433+ kind = define .CompletionItemKind .Property ,
4434+ }
4435+ }
4436+
Original file line number Diff line number Diff line change @@ -304,6 +304,21 @@ local v1 = Generic(Foo)
304304print(v1.<?bar1?>)
305305]]
306306
307+
308+ TEST [[
309+ ---@class n.Foo
310+ local Foo = {}
311+ function Foo:bar1() end
312+
313+ ---@generic T
314+ ---@param arg1 n.`T`
315+ ---@return T
316+ function Generic(arg1) print(arg1) end
317+
318+ local v1 = Generic(Foo)
319+ print(v1.<?bar1?>)
320+ ]]
321+
307322TEST [[
308323---@class Foo
309324local Foo = {}
@@ -318,6 +333,21 @@ local v1 = Generic("Foo")
318333print(v1.<?bar1?>)
319334]]
320335
336+
337+ TEST [[
338+ ---@class n.Foo
339+ local Foo = {}
340+ function Foo:<!bar1!>() end
341+
342+ ---@generic T
343+ ---@param arg1 n.`T`
344+ ---@return T
345+ function Generic(arg1) print(arg1) end
346+
347+ local v1 = Generic("Foo")
348+ print(v1.<?bar1?>)
349+ ]]
350+
321351TEST [[
322352---@class A
323353local t
You can’t perform that action at this time.
0 commit comments