summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/hover/name.lua13
-rw-r--r--server/test/find_lib/init.lua2
2 files changed, 11 insertions, 4 deletions
diff --git a/server/src/core/hover/name.lua b/server/src/core/hover/name.lua
index e5880884..763083b9 100644
--- a/server/src/core/hover/name.lua
+++ b/server/src/core/hover/name.lua
@@ -17,14 +17,21 @@ return function (source)
end
if not declarat then
-- 如果声明者没有给名字,则找一个合适的名字
- local name = value:eachInfo(function (info, src)
+ 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
- return src[1]
+ names[#names+1] = src
end
end
end)
- return name or ''
+ 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)
diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua
index 770c4121..bc60cfad 100644
--- a/server/test/find_lib/init.lua
+++ b/server/test/find_lib/init.lua
@@ -28,7 +28,7 @@ TEST 'req<require>' [[
local <?req?> = require
]]
-TEST 'xx<require>' [[
+TEST 'req<require>' [[
local req = require
local t = {
xx = req,