Skip to content

Commit e4ded21

Browse files
committed
fix(parser): 修复文档参数绑定的重复问题
新增 docsDedupe 函数,用于在绑定文档时检测并移除重复的参数文档。当同一参数存在多个文档时,优先保留非虚拟文档,确保生成的文档绑定唯一且准确。
1 parent 0187ddf commit e4ded21

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5+
* `FIX` Deduplicate documentation bindings for parameters
56

67
## 3.17.1
78
`2026-01-20`

script/parser/luadoc.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,38 @@ local function bindDocWithSources(sources, binded)
21992199
end
22002200
end
22012201

2202+
local docsDedupe = function (sources)
2203+
local removeByValue = function(bindDocs, value)
2204+
for i = #bindDocs, 1, -1 do
2205+
if bindDocs[i] == value then
2206+
table.remove(bindDocs, i)
2207+
break
2208+
end
2209+
end
2210+
end
2211+
for _, source in ipairs(sources) do
2212+
if source.bindDocs then
2213+
local docs = {}
2214+
for i = #source.bindDocs, 1, -1 do
2215+
local doc = source.bindDocs[i]
2216+
if doc.type == 'doc.param' and doc.param[1] then
2217+
local param1 = doc.param[1]
2218+
if docs[param1] then
2219+
local old = docs[param1]
2220+
if old.virtual and not doc.virtual then
2221+
removeByValue(source.bindDocs, old)
2222+
elseif not old.virtual and doc.virtual then
2223+
removeByValue(source.bindDocs, doc)
2224+
doc = old
2225+
end
2226+
end
2227+
docs[param1] = doc
2228+
end
2229+
end
2230+
end
2231+
end
2232+
end
2233+
22022234
local bindDocAccept = {
22032235
'local' , 'setlocal' , 'setglobal',
22042236
'setfield' , 'setmethod' , 'setindex' ,
@@ -2253,6 +2285,7 @@ local function bindDocs(state)
22532285
end
22542286
end
22552287
end
2288+
docsDedupe(sources)
22562289
end
22572290

22582291
local function findTouch(state, doc)

0 commit comments

Comments
 (0)