1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
local parser = require 'parser'
local matcher = require 'matcher'
rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
local start = script:find('<?', 1, true)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
local ast = parser:ast(new_script)
local vm = matcher.vm(ast)
assert(vm)
local result = matcher.hover(vm, pos)
assert(result)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1')
result = result:gsub('```lua', ''):gsub('```', ''):gsub('^[\r\n]*(.-)[\r\n]*$', '%1')
assert(expect == result)
end
end
TEST [[
local function <?x?>(a, b)
end
]]
"function x(a: any, b: any)"
TEST [[
local function x(a, b)
end
<?x?>()
]]
"function x(a: any, b: any)"
TEST [[
local mt = {}
mt.__index = mt
function mt:init(a, b, c)
return {}
end
local obj = setmetatable({}, mt)
obj:<?init?>(1, '测试')
]]
[[
function mt:init(a: number, b: string, c: any)
-> table
]]
TEST [[
local mt = {}
mt.__index = mt
function mt:init(a, b, c)
return {}
end
local obj = setmetatable({}, mt)
obj:init(1, '测试')
obj.<?init?>(obj, 1, '测试')
]]
[[
function mt.init(self: table, a: number, b: string, c: any)
-> table
]]
TEST [[
function obj.xxx()
end
obj.<?xxx?>()
]]
"function obj.xxx()"
TEST [[
obj.<?xxx?>()
]]
"function obj.xxx()"
TEST [[
local <?x?> = 1
]]
"number x = 1"
TEST [[
<?x?> = 1
]]
"number x = 1"
TEST [[
local t = {}
t.<?x?> = 1
]]
"number t.x = 1"
TEST [[
t = {}
t.<?x?> = 1
]]
"number t.x = 1"
TEST [[
local mt = {}
mt.__name = 'class'
local <?obj?> = setmetatable({}, mt)
]]
"*class obj"
TEST [[
local mt = {}
mt.name = 'class'
mt.__index = mt
local <?obj?> = setmetatable({}, mt)
]]
"*class obj"
TEST [[
local mt = {}
mt.TYPE = 'class'
mt.__index = mt
local <?obj?> = setmetatable({}, mt)
]]
"*class obj"
TEST [[
local mt = {}
mt.Class = 'class'
mt.__index = mt
local <?obj?> = setmetatable({}, mt)
]]
"*class obj"
TEST[[
local fs = require 'bee.filesystem'
local <?root?> = fs.current_path()
]]
"*bee::filesystem root"
TEST[[
('xx'):<?yy?>()
]]
"function *string:yy()"
|