diff options
author | sumneko <sumneko@hotmail.com> | 2019-06-04 18:16:55 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-06-04 18:16:55 +0800 |
commit | 543566ef37d053941c97fa680cf2e6ce04e9fd63 (patch) | |
tree | 355181fa59a4c6f22f3ef34e8857436897b91f9d | |
parent | d6807b848fba9d3d785c8140adeee95e7ed44803 (diff) | |
download | lua-language-server-543566ef37d053941c97fa680cf2e6ce04e9fd63.zip |
暂存
-rw-r--r-- | server/debugger.lua | 51 | ||||
-rw-r--r-- | server/main.lua | 10 |
2 files changed, 52 insertions, 9 deletions
diff --git a/server/debugger.lua b/server/debugger.lua new file mode 100644 index 00000000..c14cfaea --- /dev/null +++ b/server/debugger.lua @@ -0,0 +1,51 @@ +local fs = require 'bee.filesystem' +local extensionPath = fs.path(os.getenv 'USERPROFILE') / '.vscode' / 'extensions' +log.debug('Search extensions at:', extensionPath:string()) +if not fs.is_directory(extensionPath) then + log.debug('Extension path is not a directory.') + return +end + +local luaDebugs = {} +for path in extensionPath:list_directory() do + if fs.is_directory(path) then + local name = path:filename():string() + if name:find('actboy168.lua-debug-', 1, true) then + luaDebugs[#luaDebugs+1] = name + end + end +end + +if #luaDebugs == 0 then + log.debug('Cant find "actboy168.lua-debug"') + return +end + +local function getVer(filename) + local a, b, c = filename:match('(%d+)%.(%d+)%.(%d+)$') + if not a then + return 0 + end + return a * 1000000 + b * 1000 + c +end + +table.sort(luaDebugs, function (a, b) + return getVer(a) > getVer(b) +end) + +local debugPath = extensionPath / luaDebugs[1] +local cpath = "runtime/win64/lua54/?.dll" +local path = "script/?.lua" + +package.cpath = package.cpath .. ';' .. (debugPath / cpath):string() + +local function tryDebugger() + local rdebug = require "remotedebug" + local entry = package.searchpath('start_debug', (debugPath / path):string()) + local dbg = loadfile(entry)(rdebug, debugPath:string() .. '/', path, cpath) + local port = "11411" + dbg:start("listen:127.0.0.1:" .. port, true) + log.debug('Debugger startup, listen port:', port) +end + +xpcall(tryDebugger, log.debug) diff --git a/server/main.lua b/server/main.lua index 597c40bb..c9b51239 100644 --- a/server/main.lua +++ b/server/main.lua @@ -21,15 +21,7 @@ log.init(ROOT, ROOT / 'log' / 'service.log') log.info('Lua Lsp startup, root: ', ROOT) ac = {} -local function tryDebugger() - local dbg = require 'debugger' - dbg:io 'listen:127.0.0.1:11411' - dbg:start() - log.info('Debugger startup, listen port: 11411') -end - ---pcall(tryDebugger) - +--xpcall(dofile, log.debug, rootPath .. 'debugger.lua') require 'utility' require 'global_protect' local service = require 'service' |