From ac4ff86df32af5b0c0c2c730e5374130326f6129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 16 Sep 2019 22:02:33 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/vm/vm.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'server/src/vm/vm.lua') diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 7bae408c..6717a403 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -10,6 +10,7 @@ local libraryBuilder = require 'vm.library' local emmyMgr = require 'emmy.manager' local config = require 'config' local mt = require 'vm.manager' +local plugin = require 'plugin' require 'vm.module' require 'vm.raw' @@ -171,12 +172,14 @@ function mt:tryRequireOne(strValue, mode) return nil end local str = strValue:getLiteral() + local strSource = strValue:getSource() + if not strSource then + return nil + end + local raw = self.file:getText():sub(strSource.start, strSource.finish) + str = plugin.call('OnRequirePath', str, raw) or str if type(str) == 'string' then -- 支持 require 'xxx' 的转到定义 - local strSource = strValue:getSource() - if not strSource then - return nil - end self:instantSource(strSource) local uri if mode == 'require' then @@ -1307,7 +1310,7 @@ local function compile(vm, ast, lsp, uri) return vm end -return function (ast, lsp, uri) +return function (ast, lsp, uri, file) if not ast then return nil, 'Ast failed' end @@ -1321,6 +1324,7 @@ return function (ast, lsp, uri) emmyMgr = lsp and lsp.emmy or emmyMgr(), lsp = lsp, uri = uri or '', + file = file, }, mt) local suc, res = xpcall(compile, log.error, vm, ast, lsp, uri) if not suc then -- cgit v1.2.3