summaryrefslogtreecommitdiff
path: root/server/src/core/hover_name.lua
blob: d8e7b04356ed91bbebeb0257fc8fedc5a2856d6a (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

return function (result, source)
    local func = result.value
    local declarat = func.declarat or source
    if declarat then
        local key
        if declarat.type == 'name' then
            key = declarat[1]
        elseif declarat.type == 'string' then
            key = ('%q'):format(declarat[1])
        elseif declarat.type == 'number' or declarat.type == 'boolean' then
            key = tostring(declarat[1])
        elseif func.type == 'function' then
            key = ''
        elseif type(result.key) == 'string' then
            key = result.key
        else
            key = ''
        end

        local parentName = declarat.parentName

        if not parentName then
            return key or ''
        end

        if parentName == '?' then
            local parentType = result.parentValue and result.parentValue.type
            if parentType == 'table' then
            else
                parentName = '*' .. parentType
            end
        end
        if source.object then
            return parentName .. ':' .. key
        else
            if parentName then
                if declarat.index then
                    return parentName .. '[' .. key .. ']'
                else
                    return parentName .. '.' .. key
                end
            else
                return key
            end
        end
    end
    return result.key or ''
end