summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-26 21:28:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-26 21:28:33 +0800
commit32f85a5757c6fca2529e287a58d358da54a422e4 (patch)
tree2291611aed343480e51fde73a84eee6eaaf71736
parenteb0735fd4cb9530dfa6534d7424d08155e4fb619 (diff)
downloadlua-language-server-32f85a5757c6fca2529e287a58d358da54a422e4.zip
fix #1092
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion/completion.lua17
-rw-r--r--script/core/hover/init.lua17
-rw-r--r--script/vm/compiler.lua17
-rw-r--r--test/type_inference/init.lua27
5 files changed, 65 insertions, 14 deletions
diff --git a/changelog.md b/changelog.md
index 0b8fd84c..0ff20cc4 100644
--- a/changelog.md
+++ b/changelog.md
@@ -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)
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 8b50f8af..d4c20c60 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -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)
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index 9d855894..7231944a 100644
--- a/script/core/hover/init.lua
+++ b/script/core/hover/init.lua
@@ -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
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 2b63e868..75620d19 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -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
@@ -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
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index fa4249d1..817631d2 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -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'