summaryrefslogtreecommitdiff
path: root/server/src/core/references.lua
blob: 9486dafe8baa75eb2c3c7141d4f5ab1253ceffe4 (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
local findResult = require 'core.find_result'

local function parseResult(vm, result, declarat)
    local positions = {}
    local tp = result.type
    if     tp == 'local' then
        result.value:eachInfo(function (info)
            if info.source.uri == '' or not info.source.uri then
                return
            end
            if declarat or info.type == 'get' then
                positions[#positions+1] = {info.source.start, info.source.finish, info.source.uri}
            end
        end)
    elseif tp == 'field' then
        result.value:eachInfo(function (info)
            if info.source.uri == '' or not info.source.uri then
                return
            end
            if declarat or info.type == 'get' then
                positions[#positions+1] = {info.source.start, info.source.finish, info.source.uri}
            end
        end)
    elseif tp == 'label' then
        vm:eachInfo(result, function (info)
            if declarat or info.type == 'goto' then
                positions[#positions+1] = {info.source.start, info.source.finish, info.source.uri}
            end
        end)
    end
    return positions
end

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