summaryrefslogtreecommitdiff
path: root/server/src/core/hover/name.lua
blob: e58808846507294ba743afb04c729185a6d6165a (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
local getName = require 'core.name'

return function (source)
    if not source then
        return ''
    end
    local value = source:bindValue()
    if not value then
        return ''
    end
    local func = value:getFunction()
    local declarat
    if func and func:getSource() then
        declarat = func:getSource().name
    else
        declarat = source
    end
    if not declarat then
        -- 如果声明者没有给名字,则找一个合适的名字
        local name = value:eachInfo(function (info, src)
            if info.type == 'local' or info.type == 'set' or info.type == 'return' then
                if src.type == 'name' and src.uri == value.uri then
                    return src[1]
                end
            end
        end)
        return name or ''
    end

    return getName(declarat, source)
end