diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-12-28 16:58:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-28 16:58:59 +0800 |
commit | e0ff9a81c623efc1882b1fd4fad8389c7fa3ca63 (patch) | |
tree | 75d100145eef870fa4a5743b9f225a7d1fd7cd6a /script/parser/guide.lua | |
parent | f9cf323b0e0de084c74c243432d02ec1598cc6dc (diff) | |
parent | 9586b303e9b76d5da19352bd42599480c0f2c0d1 (diff) | |
download | lua-language-server-e0ff9a81c623efc1882b1fd4fad8389c7fa3ca63.zip |
Merge pull request #326 from uhziel/generic-name-string-literal
针对generic,类型参数允许是字符串字面值来表达类型
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r-- | script/parser/guide.lua | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index f6f9d7c6..4c89a09c 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -99,6 +99,7 @@ m.childMap = { ['doc.vararg'] = {'vararg', 'comment'}, ['doc.type.table'] = {'key', 'value', 'comment'}, ['doc.type.function'] = {'#args', '#returns', 'comment'}, + ['doc.type.typeliteral'] = {'node'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, } @@ -1487,6 +1488,25 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, pushQueue) end end +local function appendValidGenericType(results, status, typeName, obj) + if typeName.parent.type == 'doc.type.typeliteral' then + if obj.type == 'string' and status.interface.docType then + 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 + results[#results+1] = doc + break + end + end + end + else + -- 发现没有使用 `T`,则沿用既有逻辑直接返回实参 + results[#results+1] = obj + end +end + local function stepRefOfGeneric(status, typeUnit, args, mode) local results = {} if not args then @@ -1511,7 +1531,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] + appendValidGenericType(results, status, typeName, args[index]) end end end |