Skip to content

Commit 2e6ae80

Browse files
committed
If the ---@field of the same name has a type of fun, the duplicate-doc-field check will not be performed.
1 parent 10e1b4b commit 2e6ae80

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

changelog.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5-
* `FIX` Incorrect infer for function array annotation on tables [#2367](https://github.com/LuaLS/lua-language-server/issues/2367)
6-
* `CHG` Add server version information to `initialize` response #2996
75
* `NEW` Setting: `Lua.hint.awaitPropagate`: When enabled, --@async propagates to the caller.
6+
* `CHG` Add server version information to `initialize` response #2996
7+
* `CHG` If the `---@field` of the same name has a type of `fun`, the `duplicate-doc-field` check will not be performed.
8+
* `FIX` Incorrect infer for function array annotation on tables [#2367](https://github.com/LuaLS/lua-language-server/issues/2367)
89

910
## 3.13.4
1011
`2024-12-13`

script/core/diagnostics/duplicate-doc-field.lua

+8-24
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,18 @@ local vm = require 'vm.vm'
44
local await = require 'await'
55
local guide = require 'parser.guide'
66

7-
local function getFieldEventName(doc)
7+
local function isDocFunc(doc)
88
if not doc.extends then
9-
return nil
9+
return false
1010
end
1111
if #doc.extends.types ~= 1 then
12-
return nil
12+
return false
1313
end
1414
local docFunc = doc.extends.types[1]
1515
if docFunc.type ~= 'doc.type.function' then
16-
return nil
16+
return false
1717
end
18-
for i = 1, #docFunc.args do
19-
local arg = docFunc.args[i]
20-
if arg
21-
and arg.extends
22-
and #arg.extends.types == 1 then
23-
local literal = arg.extends.types[1]
24-
if literal.type == 'doc.type.boolean'
25-
or literal.type == 'doc.type.string'
26-
or literal.type == 'doc.type.integer' then
27-
return ('%q'):format(literal[1])
28-
end
29-
end
30-
end
31-
return nil
18+
return true
3219
end
3320

3421
---@async
@@ -47,14 +34,11 @@ return function (uri, callback)
4734
---@param field parser.object
4835
---@return string?
4936
local function viewKey(field)
37+
if isDocFunc(field) then
38+
return nil
39+
end
5040
if not cachedKeys[field] then
5141
local view = vm.viewKey(field, uri)
52-
if view then
53-
local eventName = getFieldEventName(field)
54-
if eventName then
55-
view = view .. '|' .. eventName
56-
end
57-
end
5842
cachedKeys[field] = view or false
5943
end
6044
return cachedKeys[field] or nil

test/diagnostics/duplicate-doc-field.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ local emit = {}
1515
TEST [[
1616
--- @class Emit
1717
--- @field on fun(eventName: string, cb: function)
18-
--- @field <!on!> fun(eventName: '"died"', cb: fun(i: integer))
18+
--- @field on fun(eventName: '"died"', cb: fun(i: integer))
1919
--- @field on fun(eventName: '"won"', cb: fun(s: string))
20-
--- @field <!on!> fun(eventName: '"died"', cb: fun(i: integer))
20+
--- @field on fun(eventName: '"died"', cb: fun(i: integer))
2121
local emit = {}
2222
]]
2323

0 commit comments

Comments
 (0)