diff options
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/files.lua | 7 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 3 | ||||
-rw-r--r-- | script-beta/vm/getLinks.lua | 39 | ||||
-rw-r--r-- | script-beta/vm/guideInterface.lua | 7 |
4 files changed, 46 insertions, 10 deletions
diff --git a/script-beta/files.lua b/script-beta/files.lua index 1d2b8952..ae2ac0da 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -57,6 +57,13 @@ function m.exists(uri) return m.fileMap[uri] ~= nil end +function m.asKey(uri) + if platform.OS == 'Windows' then + uri = uri:lower() + end + return uri +end + --- 设置文件文本 ---@param uri string ---@param text string diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 31836c6b..3a2d516d 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -925,6 +925,7 @@ function m.copyStatusResults(a, b) end end +--- 根据函数的调用参数,获取:调用,参数索引 function m.getCallAndArgIndex(callarg) local callargs = callarg.parent if not callargs or callargs.type ~= 'callargs' then @@ -941,7 +942,7 @@ function m.getCallAndArgIndex(callarg) return call, index end --- 根据函数调用的返回值,获取:调用的函数,参数列表,自己是第几个返回值 +--- 根据函数调用的返回值,获取:调用的函数,参数列表,自己是第几个返回值 function m.getCallValue(source) local value = m.getObjectValue(source) if not value then diff --git a/script-beta/vm/getLinks.lua b/script-beta/vm/getLinks.lua index b034fd24..41318e1c 100644 --- a/script-beta/vm/getLinks.lua +++ b/script-beta/vm/getLinks.lua @@ -3,11 +3,36 @@ local vm = require 'vm.vm' local files = require 'files' local function getFileLinks(uri) - + local links = {} + local ast = files.getAst(uri) + if not ast then + return links + end + guide.eachSpecialOf(ast.ast, 'require', function (source) + local call = source.parent + if not call or call.type ~= 'call' then + return + end + end) + return links end local function getLinksTo(uri) - + local links = {} + local mark = {} + for u in files.eachFile() do + local l = vm.getFileLinks(u) + for _, lu in ipairs(l) do + if files.eq(uri, lu) then + local ku = files.asKey(u) + if not mark[ku] then + mark[ku] = true + links[#links+1] = u + end + end + end + end + return links end function vm.getLinksTo(uri) @@ -21,11 +46,7 @@ function vm.getLinksTo(uri) end function vm.getFileLinks(uri) - local cache = vm.getCache('getFileLinks')[uri] - if cache ~= nil then - return cache - end - cache = getFileLinks(uri) - vm.getCache('getFileLinks')[uri] = cache - return cache + local cache = files.getCache(uri) + cache.links = cache.links or getFileLinks(uri) + return cache.links end diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index f3ce2740..f7a35b6d 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -7,6 +7,9 @@ local m = {} function m.searchFileReturn(results, ast, index) local returns = ast.returns + if not returns then + return + end for _, ret in ipairs(returns) do local exp = ret[index] if exp then @@ -80,3 +83,7 @@ end function vm.interface.global(name) return vm.getGlobals(name) end + +function vm.interface.links(uri) + return vm.getLinksTo(uri) +end |