diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-04-22 18:00:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-04-22 18:00:09 +0800 |
commit | 7d4230b34f1f32d371ec3f644d8468368b45d2d3 (patch) | |
tree | c7cdbf28ce927c5e992d2f12c0fd15657378bbdf | |
parent | c692372d9d37be181fddb891b2a9c91cd0ac1e0d (diff) | |
download | lua-language-server-7d4230b34f1f32d371ec3f644d8468368b45d2d3.zip |
stash
-rw-r--r-- | script/core/linker.lua | 61 | ||||
-rw-r--r-- | script/core/searcher.lua | 3 |
2 files changed, 46 insertions, 18 deletions
diff --git a/script/core/linker.lua b/script/core/linker.lua index 31c65c93..41bdbaf9 100644 --- a/script/core/linker.lua +++ b/script/core/linker.lua @@ -2,7 +2,7 @@ local util = require 'utility' local guide = require 'parser.guide' local vm = require 'vm.vm' -local Linkers +local Linkers, CreateLink local LastIDCache = {} local SPLIT_CHAR = '\x1F' local SPLIT_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']+$' @@ -254,6 +254,33 @@ local function checkForward(source) list[#list+1] = callID end end + -- 将函数的返回值映射到具体的返回值上 + if source.type == 'function' then + if source.returns then + local returns = {} + for _, rtn in ipairs(source.returns) do + for index, rtnObj in ipairs(rtn) do + if not returns[index] then + returns[index] = {} + end + returns[index][#returns[index]+1] = rtnObj + end + end + for index, rtnObjs in ipairs(returns) do + local id = ('%s%s%s%s'):format( + getID(source), + SPLIT_CHAR, + RETURN_INDEX_CHAR, + index + ) + local link = CreateLink(id) + link.forward = {} + for _, rtnObj in ipairs(rtnObjs) do + link.forward[#link.forward+1] = getID(rtnObj) + end + end + end + end if #list == 0 then return nil else @@ -335,6 +362,15 @@ local function checkBackward(source) end end +---@param link link +local function insertLinker(link) + local id = link.id + if not Linkers[id] then + Linkers[id] = {} + end + Linkers[id][#Linkers[id]+1] = link +end + ---@class link -- 当前节点的id ---@field id string @@ -349,22 +385,15 @@ end ---@param id string ---@param source? parser.guide.object ---@return link -local function createLink(id, source) - return { +function CreateLink(id, source) + local link = { id = id, source = source, forward = checkForward(source), backward = checkBackward(source), } -end - ----@param link link -local function insertLinker(link) - local id = link.id - if not Linkers[id] then - Linkers[id] = {} - end - Linkers[id][#Linkers[id]+1] = link + insertLinker(link) + return link end local m = {} @@ -411,7 +440,7 @@ function m.getLink(source) return nil end if source._link == nil then - source._link = createLink(id, source) or false + source._link = CreateLink(id, source) or false end return source._link or nil end @@ -452,11 +481,7 @@ function m.compileLinks(source) Linkers = {} root._linkers = Linkers guide.eachSource(root, function (src) - local link = m.getLink(src) - if not link then - return - end - insertLinker(link) + m.getLink(src) end) return Linkers end diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 2173f5ff..a22f9ab6 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -29,6 +29,9 @@ local m = {} ---@param mode guide.searchmode ---@param ref parser.guide.object function m.pushResult(status, mode, ref) + if not ref then + return + end local results = status.results if mode == 'def' then if ref.type == 'local' |