Skip to content

Commit

Permalink
export all globals
Browse files Browse the repository at this point in the history
fix #1943
  • Loading branch information
sumneko committed Mar 13, 2023
1 parent 6d79a66 commit a2cc107
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 46 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changelog

## 3.6.18
* `FIX` [#1943]

[#1943]: https://github.com/LuaLS/lua-language-server/issues/1943

## 3.6.17
`2023-3-9`
* `CHG` export documents: export global variables
Expand Down
88 changes: 42 additions & 46 deletions script/cli/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,41 @@ local function collectVars(global, results)
end

---@async
---@param outputPath string
function export.makeDoc(outputPath)
---@param callback fun(i, max)
function export.export(outputPath, callback)
local results = {}
local globals = vm.getAllGlobals()

local max = 0
for _ in pairs(globals) do
max = max + 1
end
local i = 0
for _, global in pairs(globals) do
if global.cate == 'variable' then
collectVars(global, results)
elseif global.cate == 'type' then
collectTypes(global, results)
end
i = i + 1
callback(i, max)
end

table.sort(results, function (a, b)
return a.name < b.name
end)

local docPath = outputPath .. '/doc.json'
jsonb.supportSparseArray = true
util.saveFile(docPath, jsonb.beautify(results))

local mdPath = doc2md.buildMD(outputPath)
return docPath, mdPath
end

---@async
---@param outputPath string
function export.makeDoc(outputPath)
ws.awaitReady(ws.rootUri)

local expandAlias = config.get(ws.rootUri, 'Lua.hover.expandAlias')
Expand All @@ -260,32 +291,11 @@ function export.makeDoc(outputPath)
await.sleep(0.1)

local prog <close> = progress.create(ws.rootUri, '正在生成文档...', 0)
local globalTypes = vm.getGlobals 'type'
local globalVars = vm.getGlobals 'variable'

local max = #globalTypes + #globalVars

for i, global in ipairs(globalTypes) do
collectTypes(global, results)
local docPath, mdPath = export.export(outputPath, function (i, max)
prog:setMessage(('%d/%d'):format(i, max))
prog:setPercentage(i / max * 100)
end

for i, global in ipairs(globalVars) do
collectVars(global, results)
prog:setMessage(('%d/%d'):format(i + #globalTypes, max))
prog:setPercentage((i + #globalTypes) / max * 100)
end

table.sort(results, function (a, b)
return a.name < b.name
prog:setPercentage((i) / max * 100)
end)

local docPath = outputPath .. '/doc.json'
jsonb.supportSparseArray = true
util.saveFile(docPath, jsonb.beautify(results))

local mdPath = doc2md.buildMD(outputPath)
return docPath, mdPath
end

Expand All @@ -308,7 +318,6 @@ function export.runCLI()
util.enableCloseFunction()

local lastClock = os.clock()
local results = {}

---@async
lclient():start(function (client)
Expand All @@ -326,11 +335,7 @@ function export.runCLI()
ws.awaitReady(rootUri)
await.sleep(0.1)

local globals = vm.getGlobals 'type'

local max = #globals
for i, global in ipairs(globals) do
collectTypes(global, results)
local docPath, mdPath = export.export(LOGPATH, function (i, max)
if os.clock() - lastClock > 0.2 then
lastClock = os.clock()
local output = '\x0D'
Expand All @@ -341,24 +346,15 @@ function export.runCLI()
.. tostring(i) .. '/' .. tostring(max)
io.write(output)
end
end
io.write('\x0D')

table.sort(results, function (a, b)
return a.name < b.name
end)
end)

local docPath = LOGPATH .. '/doc.json'
jsonb.supportSparseArray = true
util.saveFile(docPath, jsonb.beautify(results))

local mdPath = doc2md.buildMD(LOGPATH)
io.write('\x0D')

print(lang.script('CLI_DOC_DONE'
, ('[%s](%s)'):format(files.normalize(docPath), furi.encode(docPath))
, ('[%s](%s)'):format(files.normalize(mdPath), furi.encode(mdPath))
))
print(lang.script('CLI_DOC_DONE'
, ('[%s](%s)'):format(files.normalize(docPath), furi.encode(docPath))
, ('[%s](%s)'):format(files.normalize(mdPath), furi.encode(mdPath))
))
end)
end

return export

0 comments on commit a2cc107

Please sign in to comment.