summaryrefslogtreecommitdiff
path: root/server/src/matcher/find_result.lua
blob: 0b06ccad89ad385cfd4fad624418a50a3ef439b7 (plain)
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
local function isContainPos(obj, pos)
    return obj.start <= pos and obj.finish + 1 >= pos
end

return function (results, pos)
    for _, var in ipairs(results.vars) do
        for _, info in ipairs(var) do
            if isContainPos(info.source, pos) then
                return {
                    type = 'var',
                    var = var,
                    info = info,
                }
            end
        end
    end
    for _, dots in ipairs(results.dots) do
        for _, info in ipairs(dots) do
            if isContainPos(info.source, pos) then
                return {
                    type = 'dots',
                    dots = dots,
                    info = info,
                }
            end
        end
    end
    for _, label in ipairs(results.labels) do
        for _, info in ipairs(label) do
            if isContainPos(info.source, pos) then
                return {
                    type = 'label',
                    label = label,
                    info = info,
                }
            end
        end
    end
    return nil
end