Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

Commit 3bad570

Browse files
committed
1.4.4
1 parent fddf038 commit 3bad570

File tree

7 files changed

+243
-37
lines changed

7 files changed

+243
-37
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
* @Author: xuranXYS
3-
* @LastEditTime: 2024-03-29 21:21:42
3+
* @LastEditTime: 2024-03-31 15:59:57
44
* @GitHub: www.github.com/xiaoxustudio
55
* @WebSite: www.xiaoxustudio.top
66
* @Description: By xuranXYS
@@ -11,6 +11,17 @@ All notable changes to the "webgal-for-vscode" extension will be documented in t
1111

1212
## [Unreleased]
1313

14+
## [1.4.4] - 2024.3.31
15+
16+
- 修复重新调试bug
17+
- 调试功能迭代03
18+
- 调试可直接修改变量数值
19+
20+
## [1.4.3] - 2024.3.30
21+
22+
- 修复bug
23+
- 调试功能迭代02
24+
1425
## [1.4.2] - 2024.3.30
1526

1627
- 调试功能迭代

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
* @Author: xuranXYS
3-
* @LastEditTime: 2024-03-30 22:14:50
3+
* @LastEditTime: 2024-03-31 16:28:01
44
* @GitHub: www.github.com/xiaoxustudio
55
* @WebSite: www.xiaoxustudio.top
66
* @Description: By xuranXYS
@@ -87,6 +87,8 @@
8787

8888
**PS:调试变量不会实时刷新,需要手动在调试控制台回车刷新,或其他操作来触发更新**
8989

90+
**PS:左边调试变量可修改,env和scene不可修改**
91+
9092
![调试](https://raw.githubusercontent.com/xiaoxustudio/webgal-for-vscode/master/resources/test/debug.png)
9193

9294
# 部分功能展示

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "webgal-for-vscode",
33
"displayName": "webgal for VSCode",
44
"description": "webgal-for-vscode by xuran",
5-
"version": "1.4.2",
5+
"version": "1.4.4",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/xiaoxustudio/webgal-for-vscode"

resources/test/work.png

84.4 KB
Loading

src/DebugAdapter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* @Author: xuranXYS
3-
* @LastEditTime: 2024-03-30 13:53:24
3+
* @LastEditTime: 2024-03-30 22:40:40
44
* @GitHub: www.github.com/xiaoxustudio
55
* @WebSite: www.xiaoxustudio.top
66
* @Description: By xuranXYS
@@ -10,7 +10,6 @@ import { XRDebugSession } from "./DebugSession";
1010
import * as vscode from "vscode";
1111
import { fsAccessor } from "./utils/utils_novsc";
1212

13-
// first parse command line arguments to see whether the debug adapter should run as a server
1413
let port = 0;
1514
const args = process.argv.slice(2);
1615
args.forEach(function (val, index, array) {
@@ -21,7 +20,6 @@ args.forEach(function (val, index, array) {
2120
});
2221
const debug = vscode.debug.activeDebugSession;
2322
if (port > 0 && debug) {
24-
// start a server that creates a new session for every connection request
2523
console.error(`waiting for debug protocol on port ${port}`);
2624
Net.createServer((socket) => {
2725
console.error(">> accepted connection from client");
@@ -33,7 +31,6 @@ if (port > 0 && debug) {
3331
session.start(socket, socket);
3432
}).listen(port);
3533
} else if (debug) {
36-
// start a single session that communicates via stdin/stdout
3734
const session = new XRDebugSession(debug, fsAccessor);
3835
process.on("SIGTERM", () => {
3936
session.shutdown();

src/DebugSession.ts

Lines changed: 152 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/*
22
* @Author: xuranXYS
3-
* @LastEditTime: 2024-03-30 22:18:29
3+
* @LastEditTime: 2024-03-31 16:26:45
44
* @GitHub: www.github.com/xiaoxustudio
55
* @WebSite: www.xiaoxustudio.top
66
* @Description: By xuranXYS
77
*/
88
import {
9+
ExitedEvent,
910
Handles,
1011
InitializedEvent,
1112
Logger,
1213
logger,
1314
LoggingDebugSession,
14-
MemoryEvent,
1515
Scope,
1616
StackFrame,
1717
StoppedEvent,
1818
Thread,
1919
} from "@vscode/debugadapter";
2020
import { DebugProtocol } from "@vscode/debugprotocol";
2121
import { getGameData } from "./utils/utils";
22-
import { DebugSession } from "vscode";
22+
import { debug, DebugSession } from "vscode";
2323
import XRRuntime, { RuntimeVariable } from "./ws";
2424
import { FileAccessor } from "./utils/utils_novsc";
2525
import { WebSocket } from "ws";
@@ -37,7 +37,7 @@ export class XRDebugSession extends LoggingDebugSession {
3737
private _socket!: WebSocket;
3838
private _socket_real: XRRuntime;
3939
private _variableHandles = new Handles<
40-
"locals" | "globals" | RuntimeVariable
40+
"locals" | "globals" | "env" | "scene" | RuntimeVariable
4141
>();
4242
private _valuesInHex = false;
4343
constructor(_s: DebugSession, private FileAccess: FileAccessor) {
@@ -55,20 +55,20 @@ export class XRDebugSession extends LoggingDebugSession {
5555
): void {
5656
// 告诉调试器我们支持的功能
5757
response.body = response.body || {};
58+
response.body.supportsSetVariable = true;
5859
response.body.supportsConfigurationDoneRequest = true;
5960
response.body.supportsStepBack = false;
6061
response.body.supportsSteppingGranularity = false;
6162
response.body.supportsEvaluateForHovers = false;
6263
response.body.supportsStepBack = false;
63-
response.body.supportsSetVariable = false;
6464
response.body.supportsRestartFrame = false;
6565
response.body.supportsGotoTargetsRequest = false;
6666
response.body.supportsStepInTargetsRequest = false;
6767
response.body.supportsCompletionsRequest = false;
6868
response.body.supportsCancelRequest = false;
6969
response.body.supportsBreakpointLocationsRequest = false;
7070
this.sendResponse(response);
71-
console.log("initializing");
71+
console.log("(webgal)initializing");
7272
this.sendEvent(new InitializedEvent());
7373
}
7474
protected attachRequest(
@@ -77,6 +77,14 @@ export class XRDebugSession extends LoggingDebugSession {
7777
) {
7878
return this.launchRequest(response, args);
7979
}
80+
protected restartRequest(
81+
response: DebugProtocol.RestartResponse,
82+
args: DebugProtocol.RestartArguments,
83+
request?: DebugProtocol.Request | undefined
84+
): void {
85+
this._socket_real._clearFunc();
86+
this.sendResponse(response);
87+
}
8088
protected launchRequest(
8189
response: DebugProtocol.LaunchResponse,
8290
args: ILaunchRequestArguments
@@ -204,6 +212,8 @@ export class XRDebugSession extends LoggingDebugSession {
204212
response.body = {
205213
scopes: [
206214
new Scope("Locals", this._variableHandles.create("locals"), false),
215+
new Scope("Env", this._variableHandles.create("env"), false),
216+
new Scope("Scene", this._variableHandles.create("scene"), false),
207217
],
208218
};
209219
this.sendResponse(response);
@@ -212,30 +222,146 @@ export class XRDebugSession extends LoggingDebugSession {
212222
response: DebugProtocol.VariablesResponse,
213223
args: DebugProtocol.VariablesArguments
214224
): void {
215-
let vs = (this._socket_real.getLocalVariables() as RuntimeVariable[]).map(
216-
(v) => this.convertFromRuntime(v)
217-
) as DebugProtocol.Variable[];
225+
const _nfef = this._variableHandles.get(args.variablesReference);
226+
let vs: DebugProtocol.Variable[] = [];
227+
if (_nfef === "locals") {
228+
vs = (
229+
this._socket_real.getLocalVariables("var") as RuntimeVariable[]
230+
).map((v) =>
231+
this.convertFromRuntime(v, args.variablesReference)
232+
) as DebugProtocol.Variable[];
233+
} else if (_nfef === "scene") {
234+
vs = (
235+
this._socket_real.getLocalVariables("scene") as RuntimeVariable[]
236+
).map((v) =>
237+
this.convertFromRuntime(v, args.variablesReference)
238+
) as DebugProtocol.Variable[];
239+
} else if (_nfef === "env") {
240+
vs = (
241+
this._socket_real.getLocalVariables("env") as RuntimeVariable[]
242+
).map((v) =>
243+
this.convertFromRuntime(v, args.variablesReference)
244+
) as DebugProtocol.Variable[];
245+
} else {
246+
if (_nfef instanceof RuntimeVariable) {
247+
if (typeof _nfef.value === "object" && _nfef.desc === "Array") {
248+
for (let i in _nfef.value) {
249+
const _val = _nfef.value[i];
250+
const _val_name = _val.desc ?? String(_val.value);
251+
let _var = {
252+
name: _val.name,
253+
value: _val_name,
254+
variablesReference: _val.reference ?? 0,
255+
} as DebugProtocol.Variable;
256+
vs.push(_var);
257+
}
258+
} else if (typeof _nfef.value === "object" && _nfef.desc === "Object") {
259+
const _keys = _nfef.value;
260+
for (let i in _keys) {
261+
const _val = _keys[i] as RuntimeVariable;
262+
const _val_name = _val.desc ?? String(_val.value);
263+
let _var = {
264+
name: _val.name,
265+
value: _val_name,
266+
variablesReference: _val.reference ?? 0,
267+
} as DebugProtocol.Variable;
268+
vs.push(_var);
269+
}
270+
} else {
271+
let _var = {
272+
name: _nfef.name,
273+
value: String(_nfef.value),
274+
variablesReference: 0,
275+
} as DebugProtocol.Variable;
276+
vs.push(_var);
277+
}
278+
}
279+
}
218280
response.body = {
219281
variables: vs,
220282
};
221283
this.sendResponse(response);
222284
}
285+
protected setVariableRequest(
286+
response: DebugProtocol.SetVariableResponse,
287+
args: DebugProtocol.SetVariableArguments,
288+
request?: DebugProtocol.Request | undefined
289+
): void {
290+
const _origin_var = this._variableHandles.get(args.variablesReference);
291+
if (_origin_var === "locals") {
292+
this._socket.emit("runscript", `setVar:${args.name}=${args.value};`);
293+
response.body = {
294+
...args,
295+
};
296+
}
297+
this.sendResponse(response);
298+
}
223299
private formatNumber(x: number) {
224300
return this._valuesInHex ? "0x" + x.toString(16) : x.toString(10);
225301
}
226-
private convertFromRuntime(v: RuntimeVariable): DebugProtocol.Variable {
302+
private convertFromRuntime(
303+
v: RuntimeVariable,
304+
vref?: number
305+
): DebugProtocol.Variable {
227306
let dapVariable: DebugProtocol.Variable = {
228307
name: v.name,
229308
value: "???",
230309
type: typeof v.value,
231310
variablesReference: 0,
232311
evaluateName: v.name,
233312
};
234-
235-
if (Array.isArray(v.value)) {
236-
dapVariable.value = "Object";
313+
if (v.value instanceof Object) {
237314
v.reference ??= this._variableHandles.create(v);
238315
dapVariable.variablesReference = v.reference;
316+
const _to_runtimeval = (_runVal: Array<any>): RuntimeVariable[] => {
317+
let _arr: Array<any> = [];
318+
for (let _rK in _runVal) {
319+
let _rV = _runVal[_rK];
320+
const _r = new RuntimeVariable(_rK, _rV);
321+
if (Array.isArray(_rV)) {
322+
_r.reference ??= this._variableHandles.create(_r);
323+
_r.desc = "Array";
324+
_r.value = _to_runtimeval(_rV);
325+
} else if (typeof _rV === "object") {
326+
_r.reference ??= this._variableHandles.create(_r);
327+
_r.desc = "Object";
328+
_r.value = _to_runtimeval_obj(_rV);
329+
}
330+
_arr.push(_r);
331+
}
332+
return _arr;
333+
};
334+
const _to_runtimeval_obj = (_runVal: {
335+
[key: string]: any;
336+
}): RuntimeVariable[] => {
337+
let r: RuntimeVariable[] = [];
338+
const _keys = Object.keys(_runVal);
339+
for (let _rK in _keys) {
340+
const ___r = _keys[_rK];
341+
let _rV = _runVal[___r];
342+
const _r = new RuntimeVariable(___r, _rV);
343+
if (Array.isArray(_rV)) {
344+
_r.reference ??= this._variableHandles.create(_r);
345+
_r.desc = "Array";
346+
_r.value = _to_runtimeval(_rV);
347+
} else if (typeof _rV === "object") {
348+
_r.reference ??= this._variableHandles.create(_r);
349+
_r.desc = "Object";
350+
_r.value = _to_runtimeval_obj(_rV);
351+
}
352+
r.push(_r);
353+
}
354+
return r;
355+
};
356+
if (Array.isArray(v.value)) {
357+
dapVariable.value = "Array ";
358+
v.value = _to_runtimeval(v.value);
359+
v.desc = "Array";
360+
} else if (v.value) {
361+
dapVariable.value = "Object";
362+
v.value = _to_runtimeval_obj(v.value);
363+
v.desc = "Object";
364+
}
239365
} else {
240366
switch (typeof v.value) {
241367
case "number":
@@ -270,18 +396,22 @@ export class XRDebugSession extends LoggingDebugSession {
270396
switch (command) {
271397
case "updatevar":
272398
{
273-
let vs = (
274-
this._socket_real.getLocalVariables() as RuntimeVariable[]
275-
).map((v) => this.convertFromRuntime(v)) as DebugProtocol.Variable[];
276-
response.body = {
277-
variables: vs,
278-
};
279-
response.success = true;
280-
response.command = "variables";
281-
response.type = "response";
399+
// let vs = (
400+
// this._socket_real.getLocalVariables() as RuntimeVariable[]
401+
// ).map((v) => this.convertFromRuntime(v)) as DebugProtocol.Variable[];
402+
// response.body = {
403+
// variables: vs,
404+
// };
405+
// response.success = true;
406+
// response.command = "variables";
407+
// response.type = "response";
282408
this.sendResponse(response);
283409
}
284410
return;
411+
case "close":
412+
debug.stopDebugging();
413+
this.sendResponse(response);
414+
break;
285415
default:
286416
this.sendResponse(response);
287417
break;

0 commit comments

Comments
 (0)