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
|
local hover = require 'matcher.hover'
local function isContainPos(obj, pos)
if obj.start <= pos and obj.finish + 1 >= pos then
return true
end
return false
end
local function findArgCount(args, pos)
for i, arg in ipairs(args) do
if isContainPos(arg, pos) then
return i
end
end
return #args + 1
end
-- 找出范围包含pos的,且有dirty标记的call
local function findDirtyCall(vm, pos)
local results = {}
for _, call in ipairs(vm.results.calls) do
if isContainPos(call.args, pos) then
local n = findArgCount(call.args, pos)
results[#results+1] = {
func = call.func,
var = vm.results.sources[call.lastObj],
source = call.lastObj,
select = n,
args = call.args,
}
end
end
-- 可能处于 'func1(func2(' 的嵌套中,因此距离越远的函数层级越低
table.sort(results, function (a, b)
return a.args.start < b.args.start
end)
return results
end
return function (vm, pos)
local calls = findDirtyCall(vm, pos)
if #calls == 0 then
return nil
end
local hovers = {}
for _, call in ipairs(calls) do
hovers[#hovers+1] = hover(call.var, call.source, nil, call.select)
end
if #hovers == 0 then
return nil
end
return hovers
end
|