Skip to content

Commit

Permalink
fix #1092
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Apr 26, 2022
1 parent eb0735f commit 32f85a5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand Down
17 changes: 16 additions & 1 deletion script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,22 @@ local function checkLocal(state, word, position, results)
goto CONTINUE
end
if vm.getInfer(source):hasFunction() then
for _, def in ipairs(vm.getDefs(source)) do
local defs = vm.getDefs(source)
-- make sure `function` is before `doc.type.function`
local orders = {}
for i, def in ipairs(defs) do
if def.type == 'function' then
orders[def] = i - 20000
elseif def.type == 'doc.type.function' then
orders[def] = i - 10000
else
orders[def] = i
end
end
table.sort(defs, function (a, b)
return orders[a] < orders[b]
end)
for _, def in ipairs(defs) do
if def.type == 'function'
or def.type == 'doc.type.function' then
local funcLabel = name .. getParams(def, false)
Expand Down
17 changes: 16 additions & 1 deletion script/core/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@ local function getHover(source)

local oop
if vm.getInfer(source):view() == 'function' then
local defs = vm.getDefs(source)
-- make sure `function` is before `doc.type.function`
local orders = {}
for i, def in ipairs(defs) do
if def.type == 'function' then
orders[def] = i - 20000
elseif def.type == 'doc.type.function' then
orders[def] = i - 10000
else
orders[def] = i
end
end
table.sort(defs, function (a, b)
return orders[a] < orders[b]
end)
local hasFunc
for _, def in ipairs(vm.getDefs(source)) do
for _, def in ipairs(defs) do
if guide.isOOP(def) then
oop = true
end
Expand Down
17 changes: 5 additions & 12 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ local function bindDocs(source)
vm.setNode(source, vm.compileNode(ast))
return true
end
if doc.type == 'doc.overload' then
if not isParam then
vm.setNode(source, vm.compileNode(doc))
end
end
end
return false
end
Expand Down Expand Up @@ -886,18 +891,6 @@ local function compileLocal(source)
vm.compileNode(source.parent)
end

if source.bindDocs then
local isParam = source.parent.type == 'funcargs'
or source.parent.type == 'in'
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.overload' then
if not isParam then
vm.setNode(source, vm.compileNode(doc))
end
end
end
end

vm.getNode(source):setData('hasDefined', hasMarkDoc or hasMarkParam or hasMarkValue)
end

Expand Down
27 changes: 27 additions & 0 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,33 @@ local AAA
local <?x?> = AAA()
]]

TEST 'AA' [[
---@class AA
---@overload fun():AA
AAA = {}
local <?x?> = AAA()
]]

TEST 'AA' [[
---@overload fun():AA
AAA.BBB = {}
local <?x?> = AAA.BBB()
]]

TEST 'AA' [[
local AAA
---@overload fun():AA
AAA.BBB = {}
local <?x?> = AAA.BBB()
]]

TEST 'string|integer' [[
local <?x?>
x = '1'
Expand Down

0 comments on commit 32f85a5

Please sign in to comment.