diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/hover.lua | 73 | ||||
-rw-r--r-- | server/src/core/hover_function.lua | 71 |
2 files changed, 72 insertions, 72 deletions
diff --git a/server/src/core/hover.lua b/server/src/core/hover.lua index 02671eed..627a64f5 100644 --- a/server/src/core/hover.lua +++ b/server/src/core/hover.lua @@ -1,4 +1,5 @@ local findLib = require 'core.find_lib' +local getFunctionHover = require 'core.hover_function' local OriginTypes = { ['any'] = true, @@ -219,68 +220,6 @@ local function buildValueName(result, source) return result.key or '' end -local function buildValueArgs(func, source, select) - local names = {} - local values = {} - if func.args then - for i, arg in ipairs(func.args) do - names[i] = arg.key - end - end - if func.argValues then - for i, value in ipairs(func.argValues) do - values[i] = value.type - end - end - local strs = {} - local argLabel - local start = 1 - if source.object then - start = 2 - if select then - select = select + 1 - end - end - local max - if func.built then - max = #names - else - max = math.max(#names, #values) - end - for i = start, max do - local name = names[i] - local value = values[i] or 'any' - if name then - strs[#strs+1] = name .. ': ' .. value - else - strs[#strs+1] = value - end - if i == select then - argLabel = strs[#strs] - end - end - if func.hasDots then - strs[#strs+1] = '...' - end - return table.concat(strs, ', '), argLabel -end - -local function buildValueReturns(func) - if not func.hasReturn then - return '' - end - local strs = {} - if func.returns then - for i, rtn in ipairs(func.returns) do - strs[i] = rtn.type - end - end - if #strs == 0 then - strs[1] = 'any' - end - return '\n -> ' .. table.concat(strs, ', ') -end - local function getFunctionHoverAsLib(name, lib, oo, select) local args, argLabel = buildLibArgs(lib, oo, select) local returns = buildLibReturns(lib) @@ -295,16 +234,6 @@ local function getFunctionHoverAsLib(name, lib, oo, select) } end -local function getFunctionHover(name, func, source, select) - local args, argLabel = buildValueArgs(func, source, select) - local returns = buildValueReturns(func) - local title = ('function %s(%s)%s'):format(name, args, returns) - return { - label = title, - argLabel = argLabel, - } -end - local function findClass(result) -- 根据部分字段尝试找出自定义类型 local metatable = result.value.metatable diff --git a/server/src/core/hover_function.lua b/server/src/core/hover_function.lua new file mode 100644 index 00000000..08581a3e --- /dev/null +++ b/server/src/core/hover_function.lua @@ -0,0 +1,71 @@ +local function buildValueArgs(func, source, select) + local names = {} + local values = {} + if func.args then + for i, arg in ipairs(func.args) do + names[i] = arg.key + end + end + if func.argValues then + for i, value in ipairs(func.argValues) do + values[i] = value.type + end + end + local strs = {} + local argLabel + local start = 1 + if source.object then + start = 2 + if select then + select = select + 1 + end + end + local max + if func.built then + max = #names + else + max = math.max(#names, #values) + end + for i = start, max do + local name = names[i] + local value = values[i] or 'any' + if name then + strs[#strs+1] = name .. ': ' .. value + else + strs[#strs+1] = value + end + if i == select then + argLabel = strs[#strs] + end + end + if func.hasDots then + strs[#strs+1] = '...' + end + return table.concat(strs, ', '), argLabel +end + +local function buildValueReturns(func) + if not func.hasReturn then + return '' + end + local strs = {} + if func.returns then + for i, rtn in ipairs(func.returns) do + strs[i] = rtn.type + end + end + if #strs == 0 then + strs[1] = 'any' + end + return '\n -> ' .. table.concat(strs, ', ') +end + +return function (name, func, source, select) + local args, argLabel = buildValueArgs(func, source, select) + local returns = buildValueReturns(func) + local title = ('function %s(%s)%s'):format(name, args, returns) + return { + label = title, + argLabel = argLabel, + } +end |