diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 19:16:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 19:16:31 +0800 |
commit | f373707516e5edf9b7a35a8cb5a5e66b7bd63da6 (patch) | |
tree | ffd4fc537d56cf9f1d9e1670ebb681d90f815122 /script-beta | |
parent | ef682bf039cb35c97b70a36218955f8c29970f83 (diff) | |
download | lua-language-server-f373707516e5edf9b7a35a8cb5a5e66b7bd63da6.zip |
doc.vararg
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/parser/guide.lua | 57 | ||||
-rw-r--r-- | script-beta/parser/luadoc.lua | 3 |
2 files changed, 59 insertions, 1 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 35295a27..0decb789 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2414,6 +2414,22 @@ function m.isSameValue(status, a, b) return true end +function m.inferCheckLiteralTableWithDocVararg(status, source) + if #source ~= 1 then + return + end + local vararg = source[1] + if vararg.type ~= 'varargs' then + return + end + local results = m.getVarargDocType(source) + status.results[#status.results+1] = { + type = m.viewInferType(results) .. '[]', + source = source, + } + return true +end + function m.inferCheckLiteral(status, source) if source.type == 'string' then status.results = m.allocInfer { @@ -2459,6 +2475,9 @@ function m.inferCheckLiteral(status, source) } return true elseif source.type == 'table' then + if m.inferCheckLiteralTableWithDocVararg(status, source) then + return true + end status.results = m.allocInfer { type = 'table', source = source, @@ -2552,7 +2571,45 @@ function m.inferCheckDoc(status, source) end end +function m.getVarargDocType(source) + local func = m.getParentFunction(source) + if not func then + return + end + if not func.args then + return + end + for _, arg in ipairs(func.args) do + if arg.type == '...' then + if arg.bindDocs then + for _, doc in ipairs(arg.bindDocs) do + if doc.type == 'doc.vararg' then + return m.getDocTypeNames(doc.vararg) + end + end + end + end + end +end + +function m.inferCheckUpDocOfVararg(status, source) + if not source.vararg then + return + end + local results = m.getVarargDocType(source) + if not results then + return + end + for _, res in ipairs(results) do + status.results[#status.results+1] = res + end + return true +end + function m.inferCheckUpDoc(status, source) + if m.inferCheckUpDocOfVararg(status, source) then + return true + end while source.type == 'select' or source.type == 'call' do local parent = source.parent if parent.type == 'local' diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 68fef250..72974d28 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -728,7 +728,8 @@ local function bindDoc(state, lns, binded) or src.type == 'setindex' or src.type == 'tablefield' or src.type == 'tableindex' - or src.type == 'function' then + or src.type == 'function' + or src.type == '...' then src.bindDocs = binded bindSources[#bindSources+1] = src end |