Skip to content

Commit e1c38e6

Browse files
authored
Merge pull request #3293 from codrod/bug/2977-lua-autodoc-includes-global-table
Issue 2977: LuaLS autodoc is including global table in output md/json files
2 parents afe4e01 + 9e8efd2 commit e1c38e6

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `New` Omit parameter hints when the argument name matches
66
* `FIX` Fix a typo in `no-unknown` diagnostic message
7+
* `FIX` Autodoc generation so it does not include documentation for builtin Lua language features
78

89
## 3.16.1
910
`2025-12-8`

script/cli/doc/export.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,7 @@ end
274274
---@async
275275
---@return table globals
276276
function export.gatherGlobals()
277-
local all_globals = vm.getAllGlobals()
278-
local globals = {}
279-
for _, g in pairs(all_globals) do
280-
table.insert(globals, g)
281-
end
282-
return globals
277+
return util.valuesOf(vm.getExportableGlobals())
283278
end
284279

285280
---builds a lua table of based on `globals` and their elements

script/vm/global.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local globalSubs = util.multiTable(2)
2323
---@field links table<uri, vm.global.link>
2424
---@field setsCache? table<uri, parser.object[]>
2525
---@field cate vm.global.cate
26+
---@field uri string
2627
local mt = {}
2728
mt.__index = mt
2829
mt.type = 'global'
@@ -155,10 +156,11 @@ end
155156

156157
---@param cate vm.global.cate
157158
---@return vm.global
158-
local function createGlobal(name, cate)
159+
local function createGlobal(name, cate, uri)
159160
return setmetatable({
160161
name = name,
161162
cate = cate,
163+
uri = uri,
162164
links = util.multiTable(2, function ()
163165
return {
164166
sets = {},
@@ -444,7 +446,7 @@ function vm.declareGlobal(cate, name, uri)
444446
globalSubs[uri][key] = true
445447
end
446448
if not allGlobals[key] then
447-
allGlobals[key] = createGlobal(name, cate)
449+
allGlobals[key] = createGlobal(name, cate, uri)
448450
end
449451
return allGlobals[key]
450452
end
@@ -510,6 +512,19 @@ function vm.getAllGlobals()
510512
return allGlobals
511513
end
512514

515+
---@return table<string, vm.global>
516+
function vm.getExportableGlobals()
517+
local exportableGlobals = {}
518+
for key, global in pairs(allGlobals) do
519+
--If the source uri for the global matches the global variable METAPATH
520+
--then the global is a builtin Lua language feature and should not be exported
521+
if global.uri and not string.find(global.uri, METAPATH, 1, true) then
522+
exportableGlobals[key] = global
523+
end
524+
end
525+
return exportableGlobals
526+
end
527+
513528
---@param suri uri
514529
---@param cate vm.global.cate
515530
---@return parser.object[]

0 commit comments

Comments
 (0)