diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-25 01:45:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-25 01:45:29 +0800 |
commit | 01a7fa509509c49946eda72424af9542f6b5c591 (patch) | |
tree | d881754c860c865bc193341ccb9c7b75eb9611de /script-beta/core/hover/description.lua | |
parent | f15d583f7b5631e47f65a07065b69e09bbf2da66 (diff) | |
download | lua-language-server-01a7fa509509c49946eda72424af9542f6b5c591.zip |
hover显示函数参数的枚举值
Diffstat (limited to 'script-beta/core/hover/description.lua')
-rw-r--r-- | script-beta/core/hover/description.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua index 746d602e..e21ec088 100644 --- a/script-beta/core/hover/description.lua +++ b/script-beta/core/hover/description.lua @@ -73,6 +73,57 @@ local function getDocFormater() end end +local function buildLibEnum(enum) + local line = {} + if enum.default then + line[#line+1] = ' ->' + else + line[#line+1] = ' |' + end + line[#line+1] = enum.enum + if enum.description then + line[#line+1] = '--' + line[#line+1] = enum.description + end + return table.concat(line, ' ') +end + +local function getArgType(value, name) + if not value.args then + return '' + end + for _, arg in ipairs(value.args) do + if arg.name == name then + if type(arg.type) == 'table' then + return ' ' .. table.concat(arg.type, '|') + else + return arg.type and (' ' .. arg.type) or '' + end + end + end + return '' +end + +local function buildLibEnums(value) + local results = {} + local sorts = {} + + for _, enum in ipairs(value.enums) do + local name = enum.name + if not results[name] then + results[name] = { name .. ':' .. getArgType(value, name) } + sorts[#sorts+1] = name + end + results[name][#results[name]+1] = buildLibEnum(enum) + end + + local lines = {} + for _, name in ipairs(sorts) do + lines[#lines+1] = table.concat(results[name], '\n') + end + return table.concat(lines, '\n\n') +end + local function tryLibrary(source) local lib = vm.getLibrary(source) if not lib then @@ -81,12 +132,17 @@ local function tryLibrary(source) local fmt = getDocFormater() local md = markdown() if lib.value.description then + md:add('markdown', '-------------') md:add('markdown', lib.value.description:gsub('%(doc%:(.-)%)', function (tag) if fmt then return '(' .. lang.script(fmt, tag) .. ')' end end)) end + if lib.value.enums then + md:add('markdown', '-------------') + md:add('lua', buildLibEnums(lib.value)) + end if lib.value.doc and fmt then md:add('markdown', ('[%s](%s)'):format(lang.script.HOVER_VIEW_DOCUMENTS, lang.script(fmt, 'pdf-' .. lib.value.doc))) end |