diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-28 12:10:01 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-28 12:10:01 +0800 |
commit | d0ac1fdf3c0ee6b9b04ac69eaeb3c2336381ab14 (patch) | |
tree | 9a949da2ef88c8493e9e6bd606e5617e97715786 /script/core/noder.lua | |
parent | bea414d6baff2666030577311a6b6130ec3d9861 (diff) | |
download | lua-language-server-d0ac1fdf3c0ee6b9b04ac69eaeb3c2336381ab14.zip |
stash
Diffstat (limited to 'script/core/noder.lua')
-rw-r--r-- | script/core/noder.lua | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index 814936ad..545ba729 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -26,6 +26,7 @@ local ANY_FIELD_CHAR = '*' local INDEX_CHAR = '[' local RETURN_INDEX = SPLIT_CHAR .. '#' local PARAM_INDEX = SPLIT_CHAR .. '&' +local PARAM_NAME = SPLIT_CHAR .. '$' local TABLE_KEY = SPLIT_CHAR .. '<' local WEAK_TABLE_KEY = SPLIT_CHAR .. '<<' local STRING_FIELD = SPLIT_CHAR .. STRING_CHAR @@ -857,7 +858,6 @@ compileNodeMap = util.switch() : call(function (noders, id, source) pushForward(noders, id, 'dn:nil') end) - -- self -> mt:xx : case 'local' : call(function (noders, id, source) if source[1] ~= 'self' then @@ -1007,6 +1007,16 @@ compileNodeMap = util.switch() pushForward(noders, getID(src), id) end end + if source.bindSources then + for _, src in ipairs(source.bindSources) do + local paramID = sformat('%s%s%s' + , getID(src) + , PARAM_NAME + , source.param[1] + ) + pushForward(noders, paramID, id) + end + end end) : case 'doc.vararg' : call(function (noders, id, source) @@ -1054,8 +1064,8 @@ compileNodeMap = util.switch() for index, param in ipairs(source.args) do local paramID = sformat('%s%s%s' , id - , PARAM_INDEX - , index + , PARAM_NAME + , param.name[1] ) pushForward(noders, paramID, getID(param.extends)) end @@ -1130,40 +1140,12 @@ compileNodeMap = util.switch() end) : case 'function' : call(function (noders, id, source) - local hasDocReturn = {} + local hasDocReturn -- 检查 luadoc if source.bindDocs then for _, doc in ipairs(source.bindDocs) do if doc.type == 'doc.return' then - for _, rtn in ipairs(doc.returns) do - local fullID = sformat('%s%s%s' - , id - , RETURN_INDEX - , rtn.returnIndex - ) - pushForward(noders, fullID, getID(rtn)) - for _, typeUnit in ipairs(rtn.types) do - pushBackward(noders, getID(typeUnit), fullID, INFO_DEEP_AND_DONT_CROSS) - end - hasDocReturn[rtn.returnIndex] = true - end - end - if doc.type == 'doc.param' then - local paramName = doc.param[1] - if source.docParamMap then - local paramIndex = source.docParamMap[paramName] - local param = source.args[paramIndex] - if param then - pushForward(noders, getID(param), getID(doc)) - param.docParam = doc - local paramID = sformat('%s%s%s' - , id - , PARAM_INDEX - , paramIndex - ) - pushForward(noders, paramID, getID(doc.extends)) - end - end + hasDocReturn = true end if doc.type == 'doc.vararg' then if source.args then @@ -1182,26 +1164,32 @@ compileNodeMap = util.switch() end end end + if source.args then + for _, arg in ipairs(source.args) do + if arg.type == 'local' then + pushForward(noders, getID(arg), sformat('%s%s%s' + , id + , PARAM_NAME + , arg[1] + )) + else + pushForward(noders, getID(arg), sformat('%s%s%s' + , id + , PARAM_NAME + , '...' + )) + end + end + end -- 检查实体返回值 - if source.returns then - local returns = {} + if source.returns and not hasDocReturn then for _, rtn in ipairs(source.returns) do for index, rtnObj in ipairs(rtn) do - if not hasDocReturn[index] then - if not returns[index] then - returns[index] = {} - end - returns[index][#returns[index]+1] = rtnObj - end - end - end - for index, rtnObjs in ipairs(returns) do - local returnID = sformat('%s%s%s' - , id - , RETURN_INDEX - , index - ) - for _, rtnObj in ipairs(rtnObjs) do + local returnID = sformat('%s%s%s' + , id + , RETURN_INDEX + , index + ) pushForward(noders, returnID, getID(rtnObj)) pushBackward(noders, getID(rtnObj), returnID, INFO_DEEP_AND_DONT_CROSS) end @@ -1296,6 +1284,25 @@ compileNodeMap = util.switch() end end end) + : case 'doc.return' + : call(function (noders, id, source) + if not source.bindSources then + return + end + for _, rtn in ipairs(source.returns) do + for _, src in ipairs(source.bindSources) do + local fullID = sformat('%s%s%s' + , getID(src) + , RETURN_INDEX + , rtn.returnIndex + ) + pushForward(noders, fullID, getID(rtn)) + for _, typeUnit in ipairs(rtn.types) do + pushBackward(noders, getID(typeUnit), fullID, INFO_DEEP_AND_DONT_CROSS) + end + end + end + end) : case 'generic.closure' : call(function (noders, id, source) for i, rtn in ipairs(source.returns) do @@ -1436,7 +1443,7 @@ function m.hasField(id) end local next2Char = ssub(id, #firstID + 2, #firstID + 2) if next2Char == RETURN_INDEX - or next2Char == PARAM_INDEX then + or next2Char == PARAM_NAME then return false end return true @@ -1460,7 +1467,7 @@ function m.isCommonField(field) if ssub(field, 1, #RETURN_INDEX) == RETURN_INDEX then return false end - if ssub(field, 1, #PARAM_INDEX) == PARAM_INDEX then + if ssub(field, 1, #PARAM_NAME) == PARAM_NAME then return false end return true |