blob: 763083b9cd4dd2d01a02e43ec8d93348710fe6c3 (
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
|
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 names = {}
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
names[#names+1] = src
end
end
end)
if #names == 0 then
return ''
end
table.sort(names, function (a, b)
return a.id < b.id
end)
return names[1][1] or ''
end
return getName(declarat, source)
end
|