File tree 2 files changed +76
-2
lines changed
2 files changed +76
-2
lines changed Original file line number Diff line number Diff line change @@ -51,9 +51,29 @@ function mt:resolve(uri, args)
51
51
if object .literal then
52
52
-- 'number' -> `T`
53
53
for n in node :eachObject () do
54
+ local typeName = nil
55
+ local typeUri = nil
54
56
if n .type == ' string' then
57
+ typeName = n [1 ]
58
+ typeUri = guide .getUri (n )
59
+ elseif n .type == " global" and n .cate == " type" then
60
+ typeName = n :getName ()
61
+ elseif (n .type == " function" or n .type == " doc.type.function" )
62
+ and # n .returns > 0 then
55
63
--- @cast n parser.object
56
- local type = vm .declareGlobal (' type' , object .pattern and object .pattern :format (n [1 ]) or n [1 ], guide .getUri (n ))
64
+ local fret = vm .getReturnOfFunction (n , 1 )
65
+ if fret then
66
+ local compiled = vm .compileNode (fret )
67
+ local r1 = compiled and compiled [1 ]
68
+ if r1 and r1 .cate == " type" then
69
+ typeName = r1 :getName ()
70
+ end
71
+ end
72
+ end
73
+ if typeName ~= nil then
74
+ --- @cast n parser.object
75
+ local type = vm .declareGlobal (' type' ,
76
+ object .pattern and object .pattern :format (typeName ) or typeName , typeUri )
57
77
resolved [key ] = vm .createNode (type , resolved [key ])
58
78
end
59
79
end
Original file line number Diff line number Diff line change @@ -293,7 +293,7 @@ print(v1.<?bar1?>)
293
293
TEST [[
294
294
---@class Foo
295
295
local Foo = {}
296
- function Foo:bar1() end
296
+ function Foo:<! bar1!> () end
297
297
298
298
---@generic T
299
299
---@param arg1 `T`
@@ -402,6 +402,43 @@ local v1 = Generic("Foo")
402
402
print(v1.<?bar1?>)
403
403
]]
404
404
405
+ TEST [[
406
+ ---@class n.Foo.2
407
+ local nFoo2 = {}
408
+ function nFoo2:<!bar1!>() end
409
+
410
+ ---@class Foo
411
+ local Foo = {}
412
+
413
+ ---@generic T
414
+ ---@param arg1 n.`T`.2
415
+ ---@return T
416
+ function Generic(arg1) print(arg1) end
417
+
418
+ local v1 = Generic(Foo)
419
+ print(v1.<?bar1?>)
420
+ ]]
421
+
422
+ TEST [[
423
+ ---@class n.Foo.2
424
+ local nFoo2 = {}
425
+ function nFoo2:<!bar1!>() end
426
+
427
+ ---@class Foo
428
+ local Foo = {}
429
+
430
+ ---@return Foo
431
+ function returnsFoo() print("") end
432
+
433
+ ---@generic T
434
+ ---@param arg1 n.`T`.2
435
+ ---@return T
436
+ function Generic(arg1) print(arg1) end
437
+
438
+ local v1 = Generic(returnsFoo())
439
+ print(v1.<?bar1?>)
440
+ ]]
441
+
405
442
TEST [[
406
443
---@class n-Foo-2
407
444
local Foo = {}
@@ -430,6 +467,23 @@ local v1 = Generic({"Foo"})
430
467
print(v1.<?bar1?>)
431
468
]]
432
469
470
+ TEST [[
471
+ ---@class n-Foo-2
472
+ local nFoo2 = {}
473
+ function nFoo2:<!bar1!>() end
474
+
475
+ ---@class Foo
476
+ local Foo = {}
477
+
478
+ ---@generic T
479
+ ---@param arg1 n-`T`-2[]
480
+ ---@return T
481
+ function Generic(arg1) print(arg1) end
482
+
483
+ local v1 = Generic({Foo})
484
+ print(v1.<?bar1?>)
485
+ ]]
486
+
433
487
TEST [[
434
488
---@class A
435
489
local t
You can’t perform that action at this time.
0 commit comments