summaryrefslogtreecommitdiff
path: root/server/src/matcher/definition.lua
blob: 57c4be5d9b752372927402c2008608e17dc25c71 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local findResult = require 'matcher.find_result'

local function parseResult(vm, result)
    local positions = {}
    local tp = result.type
    if     tp == 'local' then
        if result.value.uri ~= vm.uri then
            for _, info in ipairs(result) do
                if info.type == 'set' then
                    positions[#positions+1] = {
                        info.source.start,
                        info.source.finish,
                        info.source.uri,
                    }
                end
            end
        else
          for _, info in ipairs(result) do
              if info.type == 'local' then
                  positions[#positions+1] = {
                    info.source.start,
                    info.source.finish,
                    info.source.uri,
                }
              end
          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,
                    info.source.uri,
                }
            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
    end
    return positions
end

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

    local positions = parseResult(vm, result)
    return positions
end