summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-16 15:28:14 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-16 15:28:14 +0800
commitd65bc946566756b7627898118e467ae8bd234341 (patch)
treeb9a48ba31b5f613ca85b4fc743f4fd88c673ff09
parent02533355addde9fc95f658390720317a884a33a9 (diff)
downloadlua-language-server-d65bc946566756b7627898118e467ae8bd234341.zip
根据配置加载调试器
-rw-r--r--.vscode/settings.json8
-rw-r--r--debugger.lua (renamed from script-beta/debugger.lua)12
-rw-r--r--main-beta.lua3
-rw-r--r--main.lua2
-rw-r--r--script-beta/pub/pub.lua10
-rw-r--r--script/debugger.lua52
6 files changed, 23 insertions, 64 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2bd043e4..c3edce21 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -10,7 +10,10 @@
"ac",
"_G",
"GC",
- "ID"
+ "ID",
+ "DEVELOP",
+ "DBGPORT",
+ "DBGWAIT"
],
"Lua.diagnostics.disable": [
],
@@ -30,5 +33,6 @@
"script/meta" : true,
},
"Lua.plugin.enable": true,
- "Lua.zzzzzz.cat": true
+ "Lua.zzzzzz.cat": true,
+ "Lua.develop.enable": true
}
diff --git a/script-beta/debugger.lua b/debugger.lua
index b77cbb0f..d5c12ff6 100644
--- a/script-beta/debugger.lua
+++ b/debugger.lua
@@ -1,4 +1,7 @@
-local wait = ...
+if not DEVELOP then
+ return
+end
+
local fs = require 'bee.filesystem'
local extensionPath = fs.path(os.getenv 'USERPROFILE' or '') / '.vscode' / 'extensions'
log.debug('Search extensions at:', extensionPath:string())
@@ -41,13 +44,12 @@ local path = "/script/?.lua"
local function tryDebugger()
local entry = assert(package.searchpath('debugger', debugPath:string() .. path))
local root = debugPath:string()
- local port = '11412'
- local addr = "127.0.0.1:" .. port
+ local addr = ("127.0.0.1:%d"):format(DBGPORT)
local dbg = loadfile(entry)('windows', root)
dbg:start(addr)
- log.debug('Debugger startup, listen port:', port)
+ log.debug('Debugger startup, listen port:', DBGPORT)
log.debug('Debugger args:', addr, root, path, cpath)
- if wait == 'wait' then
+ if DBGWAIT then
dbg:wait()
end
return dbg
diff --git a/main-beta.lua b/main-beta.lua
index b87cf6c2..1d1eecae 100644
--- a/main-beta.lua
+++ b/main-beta.lua
@@ -13,8 +13,7 @@ log.init(ROOT, ROOT / 'log' / 'service.log')
log.info('Lua Lsp startup, root: ', ROOT)
log.debug('ROOT:', ROOT:string())
---loadfile(rootPath .. '/script-beta/debugger.lua')'wait'
-dofile(rootPath .. '/script-beta/debugger.lua')
+xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
local service = require 'service'
service.start()
diff --git a/main.lua b/main.lua
index 0e8d4539..b7c10ed5 100644
--- a/main.lua
+++ b/main.lua
@@ -15,7 +15,7 @@ log.info('Lua Lsp startup, root: ', ROOT)
log.debug('ROOT:', ROOT:string())
ac = {}
---xpcall(dofile, log.debug, rootPath .. '/script/debugger.lua')
+xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
require 'utility'
local service = require 'service'
local session = service()
diff --git a/script-beta/pub/pub.lua b/script-beta/pub/pub.lua
index d00628eb..7cb9ab6d 100644
--- a/script-beta/pub/pub.lua
+++ b/script-beta/pub/pub.lua
@@ -10,12 +10,15 @@ local counter = utility.counter()
local braveTemplate = [[
package.path = %q
package.cpath = %q
+DEVELOP = %s
+DBGPORT = %d
+DBGWAIT = %s
collectgarbage 'generational'
log = require 'brave.log'
-dofile(%q)
+xpcall(dofile, log.error, %q)
local brave = require 'brave'
brave.register(%d)
]]
@@ -47,7 +50,10 @@ function m.recruitBraves(num)
thread = thread.thread(braveTemplate:format(
package.path,
package.cpath,
- (ROOT / 'script-beta' / 'debugger.lua'):string(),
+ DEVELOP,
+ DBGPORT,
+ DBGWAIT,
+ (ROOT / 'debugger.lua'):string(),
id
)),
taskMap = {},
diff --git a/script/debugger.lua b/script/debugger.lua
deleted file mode 100644
index 79b2931d..00000000
--- a/script/debugger.lua
+++ /dev/null
@@ -1,52 +0,0 @@
-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"
-
-local function tryDebugger()
- local entry = assert(package.searchpath('debugger', debugPath:string() .. path))
- local root = debugPath:string()
- local port = '11411'
- local addr = "127.0.0.1:" .. port
- local dbg = loadfile(entry)('windows', root)
- dbg:start(addr)
- dbg:wait()
- log.debug('Debugger startup, listen port:', port)
- log.debug('Debugger args:', addr, root, path, cpath)
-end
-
-xpcall(tryDebugger, log.debug)