diff --git a/changelog.md b/changelog.md index 4a9ac7170..9bd2dcfe6 100644 --- a/changelog.md +++ b/changelog.md @@ -2,9 +2,10 @@ ## Unreleased -* `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` diff --git a/script/core/diagnostics/duplicate-doc-field.lua b/script/core/diagnostics/duplicate-doc-field.lua index 6066ae531..b39def96d 100644 --- a/script/core/diagnostics/duplicate-doc-field.lua +++ b/script/core/diagnostics/duplicate-doc-field.lua @@ -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 @@ -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 diff --git a/test/diagnostics/duplicate-doc-field.lua b/test/diagnostics/duplicate-doc-field.lua index 8f3853359..925e43896 100644 --- a/test/diagnostics/duplicate-doc-field.lua +++ b/test/diagnostics/duplicate-doc-field.lua @@ -15,9 +15,9 @@ local emit = {} TEST [[ --- @class Emit --- @field on fun(eventName: string, cb: function) ---- @field 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 fun(eventName: '"died"', cb: fun(i: integer)) +--- @field on fun(eventName: '"died"', cb: fun(i: integer)) local emit = {} ]]