summaryrefslogtreecommitdiff
path: root/server-beta/src/core/definition.lua
blob: c65962689724a3d158137bf675b1cdab381049cd (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
local guide    = require 'parser.guide'
local engineer = require 'core.engineer'

return function (ast, text, offset)
    local results = {}
    guide.eachSourceContain(ast.ast, offset, function (source)
        local searcher = engineer(ast)
        searcher:eachDef(source, function (src)
            if     src.type == 'setfield'
            or     src.type == 'getfield'
            or     src.type == 'tablefield' then
                src = src.field
            elseif src.type == 'setindex'
            or     src.type == 'getindex'
            or     src.type == 'tableindex' then
                src = src.index
            elseif src.type == 'getmethod'
            or     src.type == 'setmethod' then
                src = src.method
            end
            results[#results+1] = {
                uri    = ast.uri,
                source = source,
                target = src,
            }
        end)
    end)
    if #results == 0 then
        return nil
    end
    return results
end