Skip to content

Commit fb231b6

Browse files
committed
Clean up some code in hover/init.lua loop
1 parent f7cdfee commit fb231b6

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

script/core/hover/init.lua

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,13 @@ local function getHover(source, level)
5656
local oop
5757
if vm.getInfer(source):view(guide.getUri(source)) == 'function' then
5858
local defs = vm.getDefs(source)
59+
5960
-- make sure `function` is before `doc.type.function`
60-
local orders = {}
61-
for i, def in ipairs(defs) do
62-
if def.type == 'function' then
63-
orders[def] = i - 20000
64-
elseif def.type == 'doc.type.function' then
65-
orders[def] = i - 10000
66-
else
67-
orders[def] = i
68-
end
69-
end
61+
local orders = {'function', 'doc.type.function'}
7062
table.sort(defs, function (a, b)
71-
return orders[a] < orders[b]
63+
return (orders[a.type] or (#orders + 1)) < (orders[b.type] or (#orders + 1))
7264
end)
65+
7366
local hasFunc
7467
for _, def in ipairs(defs) do
7568
if guide.isOOP(def) then
@@ -90,21 +83,15 @@ local function getHover(source, level)
9083
end
9184
else
9285
addHover(source, true, oop)
86+
9387
for _, def in ipairs(vm.getDefs(source)) do
94-
if def.type == 'global'
95-
or def.type == 'setlocal' then
96-
goto CONTINUE
97-
end
98-
if guide.isOOP(def) then
99-
oop = true
100-
end
101-
local isFunction
102-
if def.type == 'function'
103-
or def.type == 'doc.type.function' then
104-
isFunction = true
88+
if def.type ~= 'global'
89+
and def.type ~= 'setlocal' then
90+
oop = oop or guide.isOOP(def)
91+
local isFunction = def.type == 'function' or def.type == 'doc.type.function'
92+
93+
addHover(def, isFunction, oop)
10594
end
106-
addHover(def, isFunction, oop)
107-
::CONTINUE::
10895
end
10996
end
11097

0 commit comments

Comments
 (0)