diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-09-22 15:45:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-09-22 15:45:24 +0800 |
commit | 4d153059e680f1f51a97bf5269cde11d4d007e22 (patch) | |
tree | 160e0dcabd2be4ba01296a4f87ad1d6e2f9f4ae5 /script/cli | |
parent | 23055f5a6c0fc6a6d7f13ba9e635dde03b96c92f (diff) | |
download | lua-language-server-4d153059e680f1f51a97bf5269cde11d4d007e22.zip |
make docs
Diffstat (limited to 'script/cli')
-rw-r--r-- | script/cli/doc.lua | 93 |
1 files changed, 74 insertions, 19 deletions
diff --git a/script/cli/doc.lua b/script/cli/doc.lua index 69a0d04c..f268a1a7 100644 --- a/script/cli/doc.lua +++ b/script/cli/doc.lua @@ -42,31 +42,52 @@ local function packObject(source, mark) end mark[source] = true local new = {} - if #source > 0 and next(source, #source) == nil then + if (#source > 0 and next(source, #source) == nil) + or source.type == 'funcargs' then new = {} for i = 1, #source do new[i] = packObject(source[i], mark) end else for k, v in pairs(source) do - if type(k) == 'number' then - k = ('[%d]'):format(k) + if k == 'type' + or k == 'name' + or k == 'start' + or k == 'finish' + or k == 'types' then + new[k] = packObject(v, mark) end - if k == 'parent' - or k == 'typeGeneric' - or k == 'originalComment' - or k == 'node' - or k == 'class' - or k:find '_' - or k:find 'Cache' - or k:find 'bind' then - goto CONTINUE + end + if source.type == 'function' then + new['args'] = packObject(source.args, mark) + local _, _, max = vm.countReturnsOfFunction(source) + if max > 0 then + new.returns = {} + for i = 1, max do + local rtn = vm.getReturnOfFunction(source, i) + new.returns[i] = packObject(rtn) + end + end + end + if source.type == 'doc.type.table' then + new['fields'] = packObject(source.fields, mark) + end + if source.type == 'doc.field.name' + or source.type == 'doc.type.arg.name' then + new['[1]'] = packObject(source[1], mark) + new['view'] = source[1] + end + if source.type == 'doc.type.function' then + new['args'] = packObject(source.args, mark) + if source.returns then + new['returns'] = packObject(source.returns, mark) end - new[k] = packObject(v, mark) - ::CONTINUE:: end + if source.bindDocs then + new['desc'] = getDesc(source) + end + new['view'] = new['view'] or vm.getInfer(source):view(rootUri) end - new['*view*'] = vm.viewObject(source, rootUri) return new end @@ -115,12 +136,16 @@ local function collect(global) end results[#results+1] = result vm.getClassFields(rootUri, global, nil, false, function (source) - local field = {} - result.fields[#result.fields+1] = field if source.type == 'doc.field' then ---@cast source parser.object + local field = {} + result.fields[#result.fields+1] = field + if source.field.type == 'doc.field.name' then + field.field = source.field[1] + else + field.field = ('[%s]'):format(vm.viewObject(source.field, rootUri)) + end field.type = source.type - field.key = vm.viewObject(source.field, rootUri) field.file = guide.getUri(source) field.start = source.start field.finish = source.finish @@ -128,7 +153,36 @@ local function collect(global) field.extends = packObject(source.extends) return end - print(1) + if source.type == 'setfield' + or source.type == 'setmethod' then + ---@cast source parser.object + local field = {} + result.fields[#result.fields+1] = field + field.field = (source.field or source.method)[1] + field.type = source.type + field.file = guide.getUri(source) + field.start = source.start + field.finish = source.finish + field.desc = getDesc(source) + field.extends = packObject(source.value) + return + end + if source.type == 'tableindex' then + if source.index.type ~= 'string' then + return + end + ---@cast source parser.object + local field = {} + result.fields[#result.fields+1] = field + field.field = source.index[1] + field.type = source.type + field.file = guide.getUri(source) + field.start = source.start + field.finish = source.finish + field.desc = getDesc(source) + field.extends = packObject(source.value) + return + end end) end @@ -143,6 +197,7 @@ lclient():start(function (client) io.write(lang.script('CLI_DOC_INITING')) config.set(nil, 'Lua.diagnostics.enable', false) + config.set(nil, 'Lua.hover.expandAlias', false) ws.awaitReady(rootUri) await.sleep(0.1) |