Skip to content

Commit 0680396

Browse files
authored
Merge pull request #3349 from ushen-pyj/master
fix(parser): 修复文档参数绑定的重复问题
2 parents 6678d94 + 7e8c215 commit 0680396

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
* `FIX` Correct `math.type` meta return annotation to use `nil` instead of the string literal `'nil'`
67
* `FIX` Fix initial `nameStyle.config` not getting loaded in the appropriate workspace.
78
* `FIX` string.match and string.gmatch may return `string|integer?` [#3357](https://github.com/LuaLS/lua-language-server/issues/3357)

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)