Skip to content

Commit

Permalink
If the ---@field of the same name has a type of fun, the `duplica…
Browse files Browse the repository at this point in the history
…te-doc-field` check will not be performed.
  • Loading branch information
sumneko committed Dec 20, 2024
1 parent 10e1b4b commit 2e6ae80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
5 changes: 3 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

## 3.13.4
`2024-12-13`
Expand Down
32 changes: 8 additions & 24 deletions script/core/diagnostics/duplicate-doc-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ local vm = require 'vm.vm'
local await = require 'await'
local guide = require 'parser.guide'

local function getFieldEventName(doc)
local function isDocFunc(doc)
if not doc.extends then
return nil
return false
end
if #doc.extends.types ~= 1 then
return nil
return false
end
local docFunc = doc.extends.types[1]
if docFunc.type ~= 'doc.type.function' then
return nil
return false
end
for i = 1, #docFunc.args do
local arg = docFunc.args[i]
if arg
and arg.extends
and #arg.extends.types == 1 then
local literal = arg.extends.types[1]
if literal.type == 'doc.type.boolean'
or literal.type == 'doc.type.string'
or literal.type == 'doc.type.integer' then
return ('%q'):format(literal[1])
end
end
end
return nil
return true
end

---@async
Expand All @@ -47,14 +34,11 @@ return function (uri, callback)
---@param field parser.object
---@return string?
local function viewKey(field)
if isDocFunc(field) then
return nil
end
if not cachedKeys[field] then
local view = vm.viewKey(field, uri)
if view then
local eventName = getFieldEventName(field)
if eventName then
view = view .. '|' .. eventName
end
end
cachedKeys[field] = view or false
end
return cachedKeys[field] or nil
Expand Down
4 changes: 2 additions & 2 deletions test/diagnostics/duplicate-doc-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ local emit = {}
TEST [[
--- @class Emit
--- @field on fun(eventName: string, cb: function)
--- @field <!on!> fun(eventName: '"died"', cb: fun(i: integer))
--- @field on fun(eventName: '"died"', cb: fun(i: integer))
--- @field on fun(eventName: '"won"', cb: fun(s: string))
--- @field <!on!> fun(eventName: '"died"', cb: fun(i: integer))
--- @field on fun(eventName: '"died"', cb: fun(i: integer))
local emit = {}
]]

Expand Down

0 comments on commit 2e6ae80

Please # to comment.