diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 16:09:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-20 16:09:18 +0800 |
commit | 217d96a4658cd50933b3456b7f452ff26f66b8c9 (patch) | |
tree | 3a992d70ade2384fd1f3ff83e0824cece3193e11 /server/src/matcher | |
parent | b7f6abe31b42c1b55143de8273d43e56463f1be5 (diff) | |
download | lua-language-server-217d96a4658cd50933b3456b7f452ff26f66b8c9.zip |
找本地文件
Diffstat (limited to 'server/src/matcher')
-rw-r--r-- | server/src/matcher/vm.lua | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index f2b5b47b..3a272f3a 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -454,7 +454,12 @@ function mt:callRequire(func, values) return end end - self:setFunctionReturn(func, 1, nil) + local requireValue = self:createValue('boolean', nil, true) + self:setFunctionReturn(func, 1, requireValue) + self.requires[#self.requires+1] = { + str = str, + value = requireValue, + } end function mt:call(func, values) @@ -1152,7 +1157,23 @@ function mt:createEnvironment() gValue.child = envValue.child end -local function compile(ast) +function mt:loadRequires() + if not self.lsp or not self.lsp.workspace then + return + end + for _, req in ipairs(self.requires) do + local str = req.str + if type(str) == 'string' then + local uri = self.lsp.workspace:searchPath(str) + -- 如果循环require,这里会返回nil + local destVM = self.lsp:loadText(uri) + if destVM then + end + end + end +end + +local function compile(ast, lsp) local vm = setmetatable({ scope = env { locals = {}, @@ -1170,6 +1191,8 @@ local function compile(ast) }, libraryValue = {}, libraryChild = {}, + requires = {}, + lsp = lsp, }, mt) -- 创建初始环境 @@ -1178,14 +1201,17 @@ local function compile(ast) -- 执行代码 vm:doActions(ast) + -- 合并requires + vm:loadRequires() + return vm end -return function (ast) +return function (ast, lsp) if not ast then return nil end - local suc, res = xpcall(compile, log.error, ast) + local suc, res = xpcall(compile, log.error, ast, lsp) if not suc then return nil end |