diff --git a/changelog.md b/changelog.md index f712d4813..2fd6250c6 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Literal string `"async"` in LuaDoc types (e.g. `---@field mode "async" | "sync"`) is no longer mis-parsed as the `async fun` prefix [#3402](https://github.com/LuaLS/lua-language-server/issues/3402) * `FIX` A `.gitignore` line containing only whitespace no longer ignores the entire workspace [#3458](https://github.com/LuaLS/lua-language-server/issues/3458) * `FIX` `need-check-nil` diagnostic is no longer reported on safe navigation access (e.g. `x?.field`, `f?.()`, `t?.[key]`), since the optional access itself already handles the nil check. Note that a non-safe access chained after a safe one (e.g. `x.upper()?.field`) still reports, because the safe access only protects its own result. diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index a783ee3f8..6d59b09c3 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -669,7 +669,7 @@ end local function parseFunction(parent) local _, content = peekToken() - if content == 'async' then + if checkToken('name', 'async', 1) then nextToken() local pos = getStart() local tp, cont = peekToken() diff --git a/test/parser_test/ast/LuaDoc.lua b/test/parser_test/ast/LuaDoc.lua index 6b79443ea..9410f2270 100644 --- a/test/parser_test/ast/LuaDoc.lua +++ b/test/parser_test/ast/LuaDoc.lua @@ -405,6 +405,58 @@ LuaDoc [[ }, } +LuaDoc [[ +---@field mode "async" | "sync" +]] +{ + type = "doc", + start = 0, + finish = 10000, + parent = "", + [1] = { + type = "doc.field", + start = 10, + finish = 31, + range = 31, + parent = "", + field = { + type = "doc.field.name", + start = 10, + finish = 14, + parent = "", + [1] = "mode", + }, + bindComments = { + }, + extends = { + type = "doc.type", + start = 15, + finish = 31, + parent = "", + firstFinish = 31, + types = { + [1] = { + type = "doc.type.string", + start = 15, + finish = 22, + parent = "", + [1] = "async", + [2] = "\"", + }, + [2] = { + type = "doc.type.string", + start = 25, + finish = 31, + parent = "", + [1] = "sync", + [2] = "\"", + }, + }, + }, + originalComment = "", + }, +} + LuaDoc [[ ---@field private open function|string ]]