Skip to content

Commit 846297e

Browse files
committed
兼容坡脚前端
1 parent d197ccc commit 846297e

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

extension/script/backend/master/mgr.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ end
4343

4444
function mgr.init(io)
4545
socket = io
46+
--socket.debug(true)
4647
masterThread = assert(channel.query 'DbgMaster')
4748
socket.event_close(event_close)
4849
return true

extension/script/backend/master/request.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local response = require 'backend.master.response'
33
local event = require 'backend.master.event'
44
local ev = require 'backend.event'
55
local utility = require 'luadebug.utility'
6+
local resolve_config = require 'backend.master.resolve_config'
67

78
local request = {}
89

@@ -42,6 +43,7 @@ function request.initialize(req)
4243
end
4344

4445
function request.attach(req)
46+
resolve_config(req.arguments)
4547
response.success(req)
4648
state = "initializing"
4749
config = {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
--- 校验并补全调试配置
2+
--- @param config table 原始配置表
3+
--- @return table|nil config 校验后的配置表,失败时为 nil
4+
--- @return string|nil errmsg 错误信息,成功时为 nil
5+
local function resolve_config(config)
6+
-- 通用默认值填充
7+
config.type = "lua"
8+
if config.request ~= "attach" then
9+
config.request = "launch"
10+
end
11+
if type(config.name) ~= "string" then
12+
config.name = "Not specified"
13+
end
14+
if type(config.cwd) ~= "string" then
15+
if type(config.workspaceFolder) == "string" then
16+
config.cwd = config.workspaceFolder
17+
end
18+
end
19+
if type(config.stopOnEntry) ~= "boolean" then
20+
config.stopOnEntry = true
21+
end
22+
if type(config.stopOnThreadEntry) ~= "boolean" then
23+
config.stopOnThreadEntry = false
24+
end
25+
if type(config.luaVersion) ~= "string" then
26+
config.luaVersion = "lua54"
27+
end
28+
if type(config.console) ~= "string" then
29+
config.console = "internalConsole"
30+
end
31+
if type(config.sourceCoding) ~= "string" then
32+
config.sourceCoding = "utf8"
33+
end
34+
if type(config.outputCapture) ~= "table" then
35+
if config.console == "internalConsole" then
36+
config.outputCapture = {
37+
"print",
38+
"io.write",
39+
"stdout",
40+
"stderr",
41+
}
42+
else
43+
config.outputCapture = {}
44+
end
45+
end
46+
if type(config.pathFormat) ~= "string" then
47+
if config.useWSL then
48+
config.pathFormat = "path"
49+
else
50+
---@NOTICE 后端无法获取前端的操作系统,只能假设和后端是一致的
51+
local platform = require 'bee.platform'
52+
if platform.os == "windows" or platform.os == "macos" then
53+
config.pathFormat = "path"
54+
else
55+
config.pathFormat = "linuxpath"
56+
end
57+
end
58+
end
59+
60+
-- sourceMaps 校验
61+
if type(config.sourceMaps) == "table" then
62+
for _, sourceMap in ipairs(config.sourceMaps) do
63+
if type(sourceMap) ~= "table" or #sourceMap ~= 2 then
64+
error "Invalid sourceMaps."
65+
end
66+
end
67+
else
68+
config.sourceMaps = nil
69+
end
70+
71+
-- client 默认值
72+
if type(config.address) == "string" and type(config.client) ~= "boolean" then
73+
config.client = true
74+
end
75+
76+
-- configuration.variables 默认值(后端无法获取 VSCode settings,使用空表)
77+
if type(config.configuration) ~= "table" then
78+
config.configuration = {
79+
variables = {},
80+
}
81+
end
82+
end
83+
84+
return resolve_config

0 commit comments

Comments
 (0)