summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/hover/init.lua37
1 files changed, 35 insertions, 2 deletions
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,