summaryrefslogtreecommitdiff
path: root/server/src/matcher/find_result.lua
blob: e8128008a7d65076b9f2b9427f55c57f7e429578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local function isContainPos(obj, pos)
    return obj.start <= pos and obj.finish + 1 >= pos
end

local function findIn(name, group, pos)
    for _, obj in ipairs(group) do
        for _, info in ipairs(obj) do
            if isContainPos(info.source, pos) then
                return {
                    type   = name,
                    object = obj,
                    info   = info,
                }
            end
        end
    end
end

return function (results, pos)
    return findIn('local', results.locals, pos)
        or findIn('field', results.fields, pos)
        or findIn('label', results.labels, pos)
end