diff options
-rw-r--r-- | script/core/noder.lua | 21 | ||||
-rw-r--r-- | script/core/searcher.lua | 26 | ||||
-rw-r--r-- | test/basic/init.lua | 2 | ||||
-rw-r--r-- | test/basic/noder.lua (renamed from test/basic/linker.lua) | 0 |
4 files changed, 38 insertions, 11 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index cfad7129..137b4355 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -384,10 +384,6 @@ end ---@return parser.guide.object[] function m.compileNode(source) local id = getID(source) - local parent = source.parent - if not parent then - return - end if source.value then -- x = y : x -> y pushForward(id, getID(source.value)) @@ -512,6 +508,12 @@ function m.compileNode(source) pushBackward(tblID, callID) --pushBackward(indexID, callID) end + if node.special == 'require' then + local arg1 = source.args and source.args[1] + if arg1 and arg1.type == 'string' then + getNode(callID).require = arg1[1] + end + end end if source.type == 'select' then if source.vararg.type == 'call' then @@ -668,6 +670,17 @@ function m.compileNode(source) end end end + if source.type == 'main' then + if source.returns then + for _, rtn in ipairs(source.returns) do + local rtnObj = rtn[1] + if rtnObj then + pushForward('mainreturn', getID(rtnObj)) + pushBackward(getID(rtnObj), 'mainreturn') + end + end + end + end if source.type == 'generic.closure' then for i, rtn in ipairs(source.returns) do local closureID = ('%s%s%s'):format( diff --git a/script/core/searcher.lua b/script/core/searcher.lua index eb9e624f..0e94cdd7 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -2,6 +2,7 @@ local noder = require 'core.noder' local guide = require 'parser.guide' local files = require 'files' local generic = require 'core.generic' +local ws = require 'workspace' local NONE = {'NONE'} local LAST = {'LAST'} @@ -175,7 +176,8 @@ function m.getObjectValue(obj) return nil end -function m.crossSearch(status, expect, mode) +local function crossSearch(status, uri, expect, mode) + m.searchRefsByID(status, uri, expect, mode) end function m.searchRefsByID(status, uri, expect, mode) @@ -185,14 +187,13 @@ function m.searchRefsByID(status, uri, expect, mode) end local root = ast.ast local searchStep - noder.compileNode(root) + noder.compileNodes(root) status.id = expect - local mark = status.mark - - local callStack = {} + local callStack = status.callStack + local mark = {} local function search(id, field) local cmark = mark[id] if not cmark then @@ -339,6 +340,14 @@ function m.searchRefsByID(status, uri, expect, mode) end end + local function checkRequire(requireName, field) + local tid = 'mainreturn' .. (field or '') + local uris = ws.findUrisByRequirePath(requireName) + for _, ruri in ipairs(uris) do + crossSearch(status, ruri, tid, mode) + end + end + local function searchNode(id, node, field) if node.call then callStack[#callStack+1] = node.call @@ -359,6 +368,10 @@ function m.searchRefsByID(status, uri, expect, mode) checkGeneric(node.sources[1], field) end + if node.require then + checkRequire(node.require, field) + end + if node.call then callStack[#callStack] = nil end @@ -419,7 +432,8 @@ end ---@return guide.status function m.status(parentStatus, interface, deep) local status = { - mark = parentStatus and parentStatus.mark or {}, + --mark = parentStatus and parentStatus.mark or {}, + callStack = {}, results = {}, } return status diff --git a/test/basic/init.lua b/test/basic/init.lua index d3a84152..1b698493 100644 --- a/test/basic/init.lua +++ b/test/basic/init.lua @@ -1,2 +1,2 @@ require 'basic.textmerger' -require 'basic.linker' +require 'basic.noder' diff --git a/test/basic/linker.lua b/test/basic/noder.lua index 3e5e9f25..3e5e9f25 100644 --- a/test/basic/linker.lua +++ b/test/basic/noder.lua |