diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-16 22:02:33 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-16 22:02:33 +0800 |
commit | ac4ff86df32af5b0c0c2c730e5374130326f6129 (patch) | |
tree | 674e1907d70d49b81a1f91ec4f2cd1e742bf4034 /server | |
parent | 6285173c57a6a644f598dd91defa4d499176303f (diff) | |
download | lua-language-server-ac4ff86df32af5b0c0c2c730e5374130326f6129.zip |
暂存
Diffstat (limited to 'server')
-rw-r--r-- | server/main.lua | 2 | ||||
-rw-r--r-- | server/src/plugin.lua | 10 | ||||
-rw-r--r-- | server/src/service.lua | 2 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 14 |
4 files changed, 19 insertions, 9 deletions
diff --git a/server/main.lua b/server/main.lua index afb32f03..99143461 100644 --- a/server/main.lua +++ b/server/main.lua @@ -15,7 +15,7 @@ log.info('Lua Lsp startup, root: ', ROOT) log.debug('ROOT:', ROOT:string()) ac = {} ---xpcall(dofile, log.debug, rootPath .. '/debugger.lua') +xpcall(dofile, log.debug, rootPath .. '/debugger.lua') require 'utility' local service = require 'service' local session = service() diff --git a/server/src/plugin.lua b/server/src/plugin.lua index 7740c2d9..eba224d6 100644 --- a/server/src/plugin.lua +++ b/server/src/plugin.lua @@ -43,7 +43,8 @@ local function loadPluginFrom(path, root) end local function load(workspace) - Plugins = {} + Plugins = nil + if not config.config.plugin.enable then return end @@ -52,6 +53,7 @@ local function load(workspace) return end + Plugins = {} local pluginPath if workspace then pluginPath = fs.absolute(workspace.root / path) @@ -76,14 +78,18 @@ local function load(workspace) end local function call(name, ...) + if not Plugins then + return nil + end for _, plugin in ipairs(Plugins) do if type(plugin[name]) == 'function' then local suc, res = xpcall(plugin[name], showError, ...) - if suc and res then + if suc and res ~= nil then return res end end end + return nil end return { diff --git a/server/src/service.lua b/server/src/service.lua index 0b668b6d..a22dadc4 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -498,7 +498,7 @@ function mt:compileVM(uri) self:_clearGlobal(uri) local clock = os.clock() - local vm, err = buildVM(ast, self, uri) + local vm, err = buildVM(ast, self, uri, file) if vm then CachedVM[vm] = true end 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 |