summaryrefslogtreecommitdiff
path: root/script-beta/vm/guideInterface.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-07-22 18:59:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-07-22 18:59:36 +0800
commit8a3e5ec178a45a68e468a504f06452308ba2f22c (patch)
tree423436acff108a22872e3e8acbca9314c20e8007 /script-beta/vm/guideInterface.lua
parent9212e6a1b16ca4eac39667ceafd12b63cfef0bbb (diff)
downloadlua-language-server-8a3e5ec178a45a68e468a504f06452308ba2f22c.zip
用 interface 解决require问题
Diffstat (limited to 'script-beta/vm/guideInterface.lua')
-rw-r--r--script-beta/vm/guideInterface.lua47
1 files changed, 47 insertions, 0 deletions
diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua
new file mode 100644
index 00000000..db576032
--- /dev/null
+++ b/script-beta/vm/guideInterface.lua
@@ -0,0 +1,47 @@
+local vm = require 'vm.vm'
+local files = require 'files'
+local ws = require 'workspace'
+
+local m = {}
+
+function m.searchFileReturn(results, ast)
+ local returns = ast.returns
+ for _, ret in ipairs(returns) do
+ if ret[1] then
+ if ret[1].type == 'table' then
+ vm.mergeResults(results, { ret[1] })
+ else
+ local newRes = vm.getDefs(ret[1])
+ vm.mergeResults(results, newRes)
+ end
+ end
+ end
+end
+
+function m.require(args)
+ local reqName = args[1] and args[1][1]
+ if not reqName then
+ return nil
+ end
+ local results = {}
+ local uris = ws.findUrisByRequirePath(reqName, true)
+ for _, uri in ipairs(uris) do
+ local ast = files.getAst(uri)
+ if ast then
+ m.searchFileReturn(results, ast.ast)
+ end
+ end
+ return results
+end
+
+vm.interface = {}
+
+function vm.interface.call(func, args, index)
+ local lib = vm.getLibrary(func)
+ if not lib then
+ return nil
+ end
+ if lib.name == 'require' and index == 1 then
+ return m.require(args)
+ end
+end