Skip to content

Commit 13bda9d

Browse files
committed
fix: do not treat LuaDoc string "async" as async fun prefix
1 parent 66d6405 commit 13bda9d

3 files changed

Lines changed: 54 additions & 1 deletion

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` 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)
56
* `FIX` A `.gitignore` line containing only whitespace no longer ignores the entire workspace [#3458](https://github.com/LuaLS/lua-language-server/issues/3458)
67
* `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.
78

‎script/parser/luadoc.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ end
669669

670670
local function parseFunction(parent)
671671
local _, content = peekToken()
672-
if content == 'async' then
672+
if checkToken('name', 'async', 1) then
673673
nextToken()
674674
local pos = getStart()
675675
local tp, cont = peekToken()

‎test/parser_test/ast/LuaDoc.lua‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,58 @@ LuaDoc [[
405405
},
406406
}
407407

408+
LuaDoc [[
409+
---@field mode "async" | "sync"
410+
]]
411+
{
412+
type = "doc",
413+
start = 0,
414+
finish = 10000,
415+
parent = "<IGNORE>",
416+
[1] = {
417+
type = "doc.field",
418+
start = 10,
419+
finish = 31,
420+
range = 31,
421+
parent = "<IGNORE>",
422+
field = {
423+
type = "doc.field.name",
424+
start = 10,
425+
finish = 14,
426+
parent = "<IGNORE>",
427+
[1] = "mode",
428+
},
429+
bindComments = {
430+
},
431+
extends = {
432+
type = "doc.type",
433+
start = 15,
434+
finish = 31,
435+
parent = "<IGNORE>",
436+
firstFinish = 31,
437+
types = {
438+
[1] = {
439+
type = "doc.type.string",
440+
start = 15,
441+
finish = 22,
442+
parent = "<IGNORE>",
443+
[1] = "async",
444+
[2] = "\"",
445+
},
446+
[2] = {
447+
type = "doc.type.string",
448+
start = 25,
449+
finish = 31,
450+
parent = "<IGNORE>",
451+
[1] = "sync",
452+
[2] = "\"",
453+
},
454+
},
455+
},
456+
originalComment = "<IGNORE>",
457+
},
458+
}
459+
408460
LuaDoc [[
409461
---@field private open function|string
410462
]]

0 commit comments

Comments
 (0)