Skip to content

Commit 32f85a5

Browse files
committed
fix #1092
1 parent eb0735f commit 32f85a5

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 3.2.2
44
* `FIX` diagnostic: `unused-function` cannot handle recursion correctly
5+
* `FIX` [#1092](https://github.com/sumneko/lua-language-server/issues/1092)
56
* `FIX` [#1093](https://github.com/sumneko/lua-language-server/issues/1093)
67
* `FIX` runtime errors reported by telemetry, see [#1091](https://github.com/sumneko/lua-language-server/issues/1091)
78

script/core/completion/completion.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,22 @@ local function checkLocal(state, word, position, results)
303303
goto CONTINUE
304304
end
305305
if vm.getInfer(source):hasFunction() then
306-
for _, def in ipairs(vm.getDefs(source)) do
306+
local defs = vm.getDefs(source)
307+
-- make sure `function` is before `doc.type.function`
308+
local orders = {}
309+
for i, def in ipairs(defs) do
310+
if def.type == 'function' then
311+
orders[def] = i - 20000
312+
elseif def.type == 'doc.type.function' then
313+
orders[def] = i - 10000
314+
else
315+
orders[def] = i
316+
end
317+
end
318+
table.sort(defs, function (a, b)
319+
return orders[a] < orders[b]
320+
end)
321+
for _, def in ipairs(defs) do
307322
if def.type == 'function'
308323
or def.type == 'doc.type.function' then
309324
local funcLabel = name .. getParams(def, false)

script/core/hover/init.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,23 @@ local function getHover(source)
4040

4141
local oop
4242
if vm.getInfer(source):view() == 'function' then
43+
local defs = vm.getDefs(source)
44+
-- make sure `function` is before `doc.type.function`
45+
local orders = {}
46+
for i, def in ipairs(defs) do
47+
if def.type == 'function' then
48+
orders[def] = i - 20000
49+
elseif def.type == 'doc.type.function' then
50+
orders[def] = i - 10000
51+
else
52+
orders[def] = i
53+
end
54+
end
55+
table.sort(defs, function (a, b)
56+
return orders[a] < orders[b]
57+
end)
4358
local hasFunc
44-
for _, def in ipairs(vm.getDefs(source)) do
59+
for _, def in ipairs(defs) do
4560
if guide.isOOP(def) then
4661
oop = true
4762
end

script/vm/compiler.lua

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ local function bindDocs(source)
575575
vm.setNode(source, vm.compileNode(ast))
576576
return true
577577
end
578+
if doc.type == 'doc.overload' then
579+
if not isParam then
580+
vm.setNode(source, vm.compileNode(doc))
581+
end
582+
end
578583
end
579584
return false
580585
end
@@ -886,18 +891,6 @@ local function compileLocal(source)
886891
vm.compileNode(source.parent)
887892
end
888893

889-
if source.bindDocs then
890-
local isParam = source.parent.type == 'funcargs'
891-
or source.parent.type == 'in'
892-
for _, doc in ipairs(source.bindDocs) do
893-
if doc.type == 'doc.overload' then
894-
if not isParam then
895-
vm.setNode(source, vm.compileNode(doc))
896-
end
897-
end
898-
end
899-
end
900-
901894
vm.getNode(source):setData('hasDefined', hasMarkDoc or hasMarkParam or hasMarkValue)
902895
end
903896

test/type_inference/init.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,33 @@ local AAA
15521552
local <?x?> = AAA()
15531553
]]
15541554

1555+
TEST 'AA' [[
1556+
---@class AA
1557+
---@overload fun():AA
1558+
AAA = {}
1559+
1560+
1561+
local <?x?> = AAA()
1562+
]]
1563+
1564+
TEST 'AA' [[
1565+
---@overload fun():AA
1566+
AAA.BBB = {}
1567+
1568+
1569+
local <?x?> = AAA.BBB()
1570+
]]
1571+
1572+
TEST 'AA' [[
1573+
local AAA
1574+
1575+
---@overload fun():AA
1576+
AAA.BBB = {}
1577+
1578+
1579+
local <?x?> = AAA.BBB()
1580+
]]
1581+
15551582
TEST 'string|integer' [[
15561583
local <?x?>
15571584
x = '1'

0 commit comments

Comments
 (0)