From eb822b74afdec570e500b8e6778f8d6d30a8d98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 17 Aug 2020 18:29:47 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/core/hover/label.lua | 12 ++++---- script-beta/core/hover/table.lua | 59 +++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 34 deletions(-) (limited to 'script-beta/core/hover') diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua index 57b2ee8e..4f896bc7 100644 --- a/script-beta/core/hover/label.lua +++ b/script-beta/core/hover/label.lua @@ -18,9 +18,9 @@ end local function asValue(source, title) local name = buildName(source) - local class = 'any' - local infers = vm.getInfers(source) + local infers = vm.getInfers(source) local type = vm.getType(source) + local class = vm.getClass(source) local literal = vm.getLiteral(source) local cont if vm.hasType(source, 'table') then @@ -34,12 +34,12 @@ local function asValue(source, title) if cont then type = nil end - if class == 'any' then - pack[#pack+1] = type - else + if class then pack[#pack+1] = class + else + pack[#pack+1] = type end - if literal ~= '' then + if literal then pack[#pack+1] = '=' pack[#pack+1] = literal end diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index 5b086cd6..97209a4f 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -46,25 +46,6 @@ local function getField(src) return key, class or tp, literal end -local function mergeLiteral(a, b) - if not a then - return b - end - local view = util.viewLiteral(a) - if not view then - return b - end - if not b then - return { view, [view] = true } - end - if b[view] then - return b - end - b[view] = true - b[#b+1] = view - return b -end - local function buildAsHash(classes, literals) local keys = {} for k in pairs(classes) do @@ -77,9 +58,7 @@ local function buildAsHash(classes, literals) local class = classes[key] local literal = literals[key] if literal then - table.sort(literal) - local view = table.concat(literal, '|') - lines[#lines+1] = (' %s: %s = %s,'):format(key, class, view) + lines[#lines+1] = (' %s: %s = %s,'):format(key, class, literal) else lines[#lines+1] = (' %s: %s,'):format(key, class) end @@ -94,7 +73,7 @@ local function buildAsConst(classes, literals) keys[#keys+1] = k end table.sort(keys, function (a, b) - return tonumber(literals[a][1]) < tonumber(literals[b][1]) + return tonumber(literals[a]) < tonumber(literals[b]) end) local lines = {} lines[#lines+1] = '{' @@ -102,9 +81,7 @@ local function buildAsConst(classes, literals) local class = classes[key] local literal = literals[key] if literal then - table.sort(literal) - local view = table.concat(literal, '|') - lines[#lines+1] = (' %s: %s = %s,'):format(key, class, view) + lines[#lines+1] = (' %s: %s = %s,'):format(key, class, literal) else lines[#lines+1] = (' %s: %s,'):format(key, class) end @@ -113,20 +90,46 @@ local function buildAsConst(classes, literals) return table.concat(lines, '\n') end +local function mergeLiteral(literals) + local results = {} + local mark = {} + for _, value in ipairs(literals) do + if not mark[value] then + mark[value] = true + results[#results+1] = value + end + end + if #results == 0 then + return nil + end + table.sort(results) + return table.concat(results, '|') +end + return function (source) local literals = {} local classes = {} local intValue = true vm.eachField(source, function (src) local key, class, literal = getField(src) - classes[key] = guide.mergeTypes {class, classes[key]} - literals[key] = mergeLiteral(literal, literals[key]) + if not classes[key] then + classes[key] = {} + end + if not literals[key] then + literals[key] = {} + end + classes[key][#classes[key]+1] = class + literals[key][#literals[key]+1] = literal if class ~= 'integer' or not literals[key] or #literals[key] ~= 1 then intValue = false end end) + for key, class in pairs(classes) do + classes[key] = guide.mergeTypes(class) + literals[key] = mergeLiteral(literals[key]) + end if classes['[any]'] == 'any' then classes['[any]'] = nil end -- cgit v1.2.3