From 32f85a5757c6fca2529e287a58d358da54a422e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Apr 2022 21:28:33 +0800 Subject: fix #1092 --- script/core/completion/completion.lua | 17 ++++++++++++++++- script/core/hover/init.lua | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'script/core') 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 -- cgit v1.2.3