From b40b95f5aaba8da1aedbcfdea184ab7ba109c5a8 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, 9 Dec 2019 16:38:51 +0800 Subject: =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=A4=9A=E5=8E=9F=E5=9E=8B=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/core/hover/init.lua | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'script-beta/core') diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index fd8654e3..34a1afae 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -2,17 +2,50 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local getLabel = require 'core.hover.label' +local util = require 'utility' local function getHoverAsFunction(source) local values = vm.getValue(source) local labels = {} + local defs = 0 + local protos = 0 + local other = 0 for _, value in ipairs(values) do if value.type == 'function' then - labels[#labels+1] = getLabel(value.source, source) + local label = getLabel(value.source, source) + defs = defs + 1 + labels[label] = (labels[label] or 0) + 1 + if labels[label] == 1 then + protos = protos + 1 + end + else + other = other + 1 end end - local label = table.concat(labels, '\n') + if defs == 1 and other == 0 then + return { + label = next(labels), + source = source, + } + end + + -- TODO 翻译 + local lines = {} + if defs > 1 then + lines[#lines+1] = ('(%d 个定义,%d 个原型)'):format(defs, protos) + end + if other > 0 then + lines[#lines+1] = ('(%d 个非函数定义)'):format(other) + end + if defs > 1 then + for label, count in util.sortPairs(labels) do + lines[#lines+1] = ('(%d) %s'):format(count, label) + end + else + lines[#lines+1] = next(labels) + end + local label = table.concat(lines, '\n') return { label = label, source = source, -- cgit v1.2.3