summaryrefslogtreecommitdiff
path: root/script/parser/luadoc.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-25 01:23:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-25 01:23:50 +0800
commit125d943a7faec97b7169d0088a12ba6a44a14c16 (patch)
tree40b5a7d8d55571334c5ddecd302fe89c34969c84 /script/parser/luadoc.lua
parent163da759468164bc020fb4801bf06f1a190af7ad (diff)
downloadlua-language-server-125d943a7faec97b7169d0088a12ba6a44a14c16.zip
add `---@cast`
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r--script/parser/luadoc.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 3b50db34..e10ef356 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -53,6 +53,7 @@ Symbol <- ({} {
/ '...'
/ '['
/ ']'
+ / '-' !'-'
} {})
-> Symbol
]], {
@@ -1205,6 +1206,70 @@ local docSwitch = util.switch()
result.finish = getFinish()
return result
end)
+ : case 'cast'
+ : call(function ()
+ local result = {
+ type = 'doc.cast',
+ start = getFinish(),
+ finish = getFinish(),
+ casts = {},
+ }
+
+ local loc = parseName('doc.cast.name', result)
+ if not loc then
+ pushWarning {
+ type = 'LUADOC_MISS_LOCAL_NAME',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ return result
+ end
+
+ result.loc = loc
+ result.finish = loc.finish
+
+ while true do
+ local block = {
+ type = 'doc.cast.block',
+ parent = result,
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ result.casts[#result.casts+1] = block
+ if checkToken('symbol', '+', 1) then
+ block.mode = '+'
+ nextToken()
+ block.start = getStart()
+ block.finish = getFinish()
+ elseif checkToken('symbol', '-', 1) then
+ block.mode = '-'
+ nextToken()
+ block.start = getStart()
+ block.finish = getFinish()
+ end
+
+ if checkToken('symbol', '?', 1) then
+ block.optional = true
+ nextToken()
+ block.start = block.start or getStart()
+ block.finish = block.finish
+ else
+ block.extends = parseType(block)
+ if block.extends then
+ block.start = block.start or block.extends.start
+ block.finish = block.extends.finish
+ end
+ end
+
+ if checkToken('symbol', ',', 1) then
+ nextToken()
+ else
+ break
+ end
+ end
+
+ return result
+ end)
local function convertTokens()
local tp, text = nextToken()
@@ -1313,6 +1378,9 @@ local function isNextLine(binded, doc)
return false
end
end
+ if doc.type == 'doc.cast' then
+ return false
+ end
local lastRow = guide.rowColOf(lastDoc.finish)
local newRow = guide.rowColOf(doc.start)
return newRow - lastRow == 1