diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/core/command/solve.lua | 2 | ||||
-rw-r--r-- | script/core/document-symbol.lua | 2 | ||||
-rw-r--r-- | script/core/linker.lua | 30 | ||||
-rw-r--r-- | script/core/searcher.lua | 46 |
4 files changed, 53 insertions, 27 deletions
diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua index c2cc103e..dc23e7af 100644 --- a/script/core/command/solve.lua +++ b/script/core/command/solve.lua @@ -1,5 +1,5 @@ local files = require 'files' -local searcher = require 'core.searcher' +local guide = require 'parser.guide' local proto = require 'proto' local lang = require 'language' diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua index be16e8e0..e36ba29b 100644 --- a/script/core/document-symbol.lua +++ b/script/core/document-symbol.lua @@ -1,6 +1,6 @@ local await = require 'await' local files = require 'files' -local searcher = require 'core.searcher' +local guide = require 'parser.guide' local define = require 'proto.define' local util = require 'utility' diff --git a/script/core/linker.lua b/script/core/linker.lua index e31d4eb9..31c65c93 100644 --- a/script/core/linker.lua +++ b/script/core/linker.lua @@ -211,6 +211,14 @@ local function checkForward(source) end end end + -- self -> mt:xx + if source.tag == 'self' then + local func = guide.getParentFunction(source) + local setmethod = func.parent + if setmethod and setmethod.type == 'setmethod' then + list[#list+1] = getID(setmethod.node) + end + end -- source 绑定的 @class/@type local bindDocs = source.bindDocs if bindDocs then @@ -232,6 +240,20 @@ local function checkForward(source) list[#list+1] = getID(source.class) list[#list+1] = getID(source.extends) end + -- 将call的返回值接收映射到函数返回值上 + if source.type == 'select' then + local call = source.vararg + if call.type == 'call' then + local node = call.node + local callID = ('%s%s%s%s'):format( + getID(node), + SPLIT_CHAR, + RETURN_INDEX_CHAR, + source.index + ) + list[#list+1] = callID + end + end if #list == 0 then return nil else @@ -252,14 +274,6 @@ local function checkBackward(source) if parent.value == source then list[#list+1] = getID(parent) end - -- self -> mt:xx - if source.tag == 'self' then - local func = guide.getParentFunction(source) - local setmethod = func.parent - if setmethod and setmethod.type == 'setmethod' then - list[#list+1] = getID(setmethod.node) - end - end -- name 映射回 class 与 type if source.type == 'doc.class.name' or source.type == 'doc.type.name' then diff --git a/script/core/searcher.lua b/script/core/searcher.lua index f57e9ad7..2173f5ff 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -2,6 +2,8 @@ local linker = require 'core.linker' local guide = require 'parser.guide' local files = require 'files' +local UNI_CHAR = '~' + local function checkFunctionReturn(source) if source.parent and source.parent.type == 'return' then @@ -141,7 +143,20 @@ function m.searchRefsByID(status, uri, expect, mode) local root = ast.ast linker.compileLinks(root) - local search + local mark = status.mark + local queueIDs = {} + local queueFields = {} + local index = 0 + + local function search(id, field) + if mark[id] then + return + end + mark[id] = true + index = index + 1 + queueIDs[index] = id + queueFields[index] = field + end local function checkLastID(id, field) local lastID = linker.getLastID(id) @@ -198,27 +213,27 @@ function m.searchRefsByID(status, uri, expect, mode) if not link.backward then return end + if mode == 'def' and not field then + return + end for _, id in ipairs(link.backward) do searchID(id, field) end end - local stackCount = 0 - local mark = status.mark - search = function (id, field) - if not id then - return - end - if mark[id] then + search(expect) + searchFunction(expect) + + for _ = 1, 1000 do + if index <= 0 then return end - mark[id] = true - stackCount = stackCount + 1 + local id = queueIDs[index] + local field = queueFields[index] + index = index - 1 + local links = linker.getLinksByID(root, id) if links then - if stackCount >= 100 then - error('stack overflow') - end for _, eachLink in ipairs(links) do if field == nil then m.pushResult(status, mode, eachLink.source) @@ -228,11 +243,8 @@ function m.searchRefsByID(status, uri, expect, mode) end end checkLastID(id, field) - stackCount = stackCount - 1 end - - search(expect) - searchFunction(expect) + error('too large') end ---搜索对象的引用 |