diff options
author | Lei Zhu <uhziel@gmail.com> | 2020-12-24 19:56:15 +0800 |
---|---|---|
committer | Lei Zhu <uhziel@gmail.com> | 2020-12-24 19:56:15 +0800 |
commit | 0161e51df7f8aed8406e964316eb98926a52c023 (patch) | |
tree | d73925ee20ca0fb60d31c75a0e0ef68bba669de9 /script/parser | |
parent | cb28b668db32b7afe29c9d01dfcc700b0377e266 (diff) | |
download | lua-language-server-0161e51df7f8aed8406e964316eb98926a52c023.zip |
针对generic,类型参数允许是字符串字面值来表达类型
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/guide.lua | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index a6b11744..2932f159 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1478,6 +1478,27 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) end end +local function toValidGenericType(status, obj) + if obj.type ~= 'string' then + return obj + end + + if not status.interface.docType then + return obj + end + + local docs = status.interface.docType(obj[1]) + for i = 1, #docs do + local doc = docs[i] + if doc.type == 'doc.class.name' + or doc.type == 'doc.alias.name' then + return doc + end + end + + return obj +end + local function stepRefOfGeneric(status, typeUnit, args, mode) if not args then return nil @@ -1502,7 +1523,7 @@ local function stepRefOfGeneric(status, typeUnit, args, mode) and source.parent.type == 'funcargs' then for index, arg in ipairs(source.parent) do if arg == source then - results[#results+1] = args[index] + results[#results+1] = toValidGenericType(status, args[index]) end end end |