diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-09 16:38:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-09 16:38:51 +0800 |
commit | b40b95f5aaba8da1aedbcfdea184ab7ba109c5a8 (patch) | |
tree | 40ef2a838aec56e7e937884a43f461a2bb8dd048 /script-beta/core | |
parent | a0b38e22f3c20c2cff737d489c12eee740c9f6f5 (diff) | |
download | lua-language-server-b40b95f5aaba8da1aedbcfdea184ab7ba109c5a8.zip |
函数多原型定义
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/hover/init.lua | 37 |
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, |