summaryrefslogtreecommitdiff
path: root/server/src/matcher/implementation.lua
blob: 72d2411f0abf989504373b68ccb5c6173d75fdd0 (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
local findResult = require 'matcher.find_result'

local function parseResult(result)
    local positions = {}
    local tp = result.type
    if     tp == 'local' then
        for _, info in ipairs(result) do
            if info.type == 'set' then
                positions[#positions+1] = {info.source.start, info.source.finish}
            end
        end
    elseif tp == 'field' then
        for _, info in ipairs(result) do
            if info.type == 'set' then
                positions[#positions+1] = {info.source.start, info.source.finish}
            end
        end
    elseif tp == 'label' then
        for _, info in ipairs(result) do
            if info.type == 'set' then
                positions[#positions+1] = {info.source.start, info.source.finish}
            end
        end
    else
        error('Unknow result type:' .. result.type)
    end
    return positions
end

return function (vm, pos)
    local result = findResult(vm, pos)
    if not result then
        return nil
    end
    local positions = parseResult(result)
    return positions
end