Skip to content

Commit

Permalink
1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxustudio committed Mar 31, 2024
1 parent fddf038 commit 3bad570
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 37 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
* @Author: xuranXYS
* @LastEditTime: 2024-03-29 21:21:42
* @LastEditTime: 2024-03-31 15:59:57
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand All @@ -11,6 +11,17 @@ All notable changes to the "webgal-for-vscode" extension will be documented in t

## [Unreleased]

## [1.4.4] - 2024.3.31

- 修复重新调试bug
- 调试功能迭代03
- 调试可直接修改变量数值

## [1.4.3] - 2024.3.30

- 修复bug
- 调试功能迭代02

## [1.4.2] - 2024.3.30

- 调试功能迭代
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
* @Author: xuranXYS
* @LastEditTime: 2024-03-30 22:14:50
* @LastEditTime: 2024-03-31 16:28:01
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand Down Expand Up @@ -87,6 +87,8 @@

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

**PS:左边调试变量可修改,env和scene不可修改**

![调试](https://raw.githubusercontent.com/xiaoxustudio/webgal-for-vscode/master/resources/test/debug.png)

# 部分功能展示
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webgal-for-vscode",
"displayName": "webgal for VSCode",
"description": "webgal-for-vscode by xuran",
"version": "1.4.2",
"version": "1.4.4",
"repository": {
"type": "git",
"url": "https://github.com/xiaoxustudio/webgal-for-vscode"
Expand Down
Binary file modified resources/test/work.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/DebugAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @Author: xuranXYS
* @LastEditTime: 2024-03-30 13:53:24
* @LastEditTime: 2024-03-30 22:40:40
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand All @@ -10,7 +10,6 @@ import { XRDebugSession } from "./DebugSession";
import * as vscode from "vscode";
import { fsAccessor } from "./utils/utils_novsc";

// first parse command line arguments to see whether the debug adapter should run as a server
let port = 0;
const args = process.argv.slice(2);
args.forEach(function (val, index, array) {
Expand All @@ -21,7 +20,6 @@ args.forEach(function (val, index, array) {
});
const debug = vscode.debug.activeDebugSession;
if (port > 0 && debug) {
// start a server that creates a new session for every connection request
console.error(`waiting for debug protocol on port ${port}`);
Net.createServer((socket) => {
console.error(">> accepted connection from client");
Expand All @@ -33,7 +31,6 @@ if (port > 0 && debug) {
session.start(socket, socket);
}).listen(port);
} else if (debug) {
// start a single session that communicates via stdin/stdout
const session = new XRDebugSession(debug, fsAccessor);
process.on("SIGTERM", () => {
session.shutdown();
Expand Down
174 changes: 152 additions & 22 deletions src/DebugSession.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
* @Author: xuranXYS
* @LastEditTime: 2024-03-30 22:18:29
* @LastEditTime: 2024-03-31 16:26:45
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
*/
import {
ExitedEvent,
Handles,
InitializedEvent,
Logger,
logger,
LoggingDebugSession,
MemoryEvent,
Scope,
StackFrame,
StoppedEvent,
Thread,
} from "@vscode/debugadapter";
import { DebugProtocol } from "@vscode/debugprotocol";
import { getGameData } from "./utils/utils";
import { DebugSession } from "vscode";
import { debug, DebugSession } from "vscode";
import XRRuntime, { RuntimeVariable } from "./ws";
import { FileAccessor } from "./utils/utils_novsc";
import { WebSocket } from "ws";
Expand All @@ -37,7 +37,7 @@ export class XRDebugSession extends LoggingDebugSession {
private _socket!: WebSocket;
private _socket_real: XRRuntime;
private _variableHandles = new Handles<
"locals" | "globals" | RuntimeVariable
"locals" | "globals" | "env" | "scene" | RuntimeVariable
>();
private _valuesInHex = false;
constructor(_s: DebugSession, private FileAccess: FileAccessor) {
Expand All @@ -55,20 +55,20 @@ export class XRDebugSession extends LoggingDebugSession {
): void {
// 告诉调试器我们支持的功能
response.body = response.body || {};
response.body.supportsSetVariable = true;
response.body.supportsConfigurationDoneRequest = true;
response.body.supportsStepBack = false;
response.body.supportsSteppingGranularity = false;
response.body.supportsEvaluateForHovers = false;
response.body.supportsStepBack = false;
response.body.supportsSetVariable = false;
response.body.supportsRestartFrame = false;
response.body.supportsGotoTargetsRequest = false;
response.body.supportsStepInTargetsRequest = false;
response.body.supportsCompletionsRequest = false;
response.body.supportsCancelRequest = false;
response.body.supportsBreakpointLocationsRequest = false;
this.sendResponse(response);
console.log("initializing");
console.log("(webgal)initializing");
this.sendEvent(new InitializedEvent());
}
protected attachRequest(
Expand All @@ -77,6 +77,14 @@ export class XRDebugSession extends LoggingDebugSession {
) {
return this.launchRequest(response, args);
}
protected restartRequest(
response: DebugProtocol.RestartResponse,
args: DebugProtocol.RestartArguments,
request?: DebugProtocol.Request | undefined
): void {
this._socket_real._clearFunc();
this.sendResponse(response);
}
protected launchRequest(
response: DebugProtocol.LaunchResponse,
args: ILaunchRequestArguments
Expand Down Expand Up @@ -204,6 +212,8 @@ export class XRDebugSession extends LoggingDebugSession {
response.body = {
scopes: [
new Scope("Locals", this._variableHandles.create("locals"), false),
new Scope("Env", this._variableHandles.create("env"), false),
new Scope("Scene", this._variableHandles.create("scene"), false),
],
};
this.sendResponse(response);
Expand All @@ -212,30 +222,146 @@ export class XRDebugSession extends LoggingDebugSession {
response: DebugProtocol.VariablesResponse,
args: DebugProtocol.VariablesArguments
): void {
let vs = (this._socket_real.getLocalVariables() as RuntimeVariable[]).map(
(v) => this.convertFromRuntime(v)
) as DebugProtocol.Variable[];
const _nfef = this._variableHandles.get(args.variablesReference);
let vs: DebugProtocol.Variable[] = [];
if (_nfef === "locals") {
vs = (
this._socket_real.getLocalVariables("var") as RuntimeVariable[]
).map((v) =>
this.convertFromRuntime(v, args.variablesReference)
) as DebugProtocol.Variable[];
} else if (_nfef === "scene") {
vs = (
this._socket_real.getLocalVariables("scene") as RuntimeVariable[]
).map((v) =>
this.convertFromRuntime(v, args.variablesReference)
) as DebugProtocol.Variable[];
} else if (_nfef === "env") {
vs = (
this._socket_real.getLocalVariables("env") as RuntimeVariable[]
).map((v) =>
this.convertFromRuntime(v, args.variablesReference)
) as DebugProtocol.Variable[];
} else {
if (_nfef instanceof RuntimeVariable) {
if (typeof _nfef.value === "object" && _nfef.desc === "Array") {
for (let i in _nfef.value) {
const _val = _nfef.value[i];
const _val_name = _val.desc ?? String(_val.value);
let _var = {
name: _val.name,
value: _val_name,
variablesReference: _val.reference ?? 0,
} as DebugProtocol.Variable;
vs.push(_var);
}
} else if (typeof _nfef.value === "object" && _nfef.desc === "Object") {
const _keys = _nfef.value;
for (let i in _keys) {
const _val = _keys[i] as RuntimeVariable;
const _val_name = _val.desc ?? String(_val.value);
let _var = {
name: _val.name,
value: _val_name,
variablesReference: _val.reference ?? 0,
} as DebugProtocol.Variable;
vs.push(_var);
}
} else {
let _var = {
name: _nfef.name,
value: String(_nfef.value),
variablesReference: 0,
} as DebugProtocol.Variable;
vs.push(_var);
}
}
}
response.body = {
variables: vs,
};
this.sendResponse(response);
}
protected setVariableRequest(
response: DebugProtocol.SetVariableResponse,
args: DebugProtocol.SetVariableArguments,
request?: DebugProtocol.Request | undefined
): void {
const _origin_var = this._variableHandles.get(args.variablesReference);
if (_origin_var === "locals") {
this._socket.emit("runscript", `setVar:${args.name}=${args.value};`);
response.body = {
...args,
};
}
this.sendResponse(response);
}
private formatNumber(x: number) {
return this._valuesInHex ? "0x" + x.toString(16) : x.toString(10);
}
private convertFromRuntime(v: RuntimeVariable): DebugProtocol.Variable {
private convertFromRuntime(
v: RuntimeVariable,
vref?: number
): DebugProtocol.Variable {
let dapVariable: DebugProtocol.Variable = {
name: v.name,
value: "???",
type: typeof v.value,
variablesReference: 0,
evaluateName: v.name,
};

if (Array.isArray(v.value)) {
dapVariable.value = "Object";
if (v.value instanceof Object) {
v.reference ??= this._variableHandles.create(v);
dapVariable.variablesReference = v.reference;
const _to_runtimeval = (_runVal: Array<any>): RuntimeVariable[] => {
let _arr: Array<any> = [];
for (let _rK in _runVal) {
let _rV = _runVal[_rK];
const _r = new RuntimeVariable(_rK, _rV);
if (Array.isArray(_rV)) {
_r.reference ??= this._variableHandles.create(_r);
_r.desc = "Array";
_r.value = _to_runtimeval(_rV);
} else if (typeof _rV === "object") {
_r.reference ??= this._variableHandles.create(_r);
_r.desc = "Object";
_r.value = _to_runtimeval_obj(_rV);
}
_arr.push(_r);
}
return _arr;
};
const _to_runtimeval_obj = (_runVal: {
[key: string]: any;
}): RuntimeVariable[] => {
let r: RuntimeVariable[] = [];
const _keys = Object.keys(_runVal);
for (let _rK in _keys) {
const ___r = _keys[_rK];
let _rV = _runVal[___r];
const _r = new RuntimeVariable(___r, _rV);
if (Array.isArray(_rV)) {
_r.reference ??= this._variableHandles.create(_r);
_r.desc = "Array";
_r.value = _to_runtimeval(_rV);
} else if (typeof _rV === "object") {
_r.reference ??= this._variableHandles.create(_r);
_r.desc = "Object";
_r.value = _to_runtimeval_obj(_rV);
}
r.push(_r);
}
return r;
};
if (Array.isArray(v.value)) {
dapVariable.value = "Array ";
v.value = _to_runtimeval(v.value);
v.desc = "Array";
} else if (v.value) {
dapVariable.value = "Object";
v.value = _to_runtimeval_obj(v.value);
v.desc = "Object";
}
} else {
switch (typeof v.value) {
case "number":
Expand Down Expand Up @@ -270,18 +396,22 @@ export class XRDebugSession extends LoggingDebugSession {
switch (command) {
case "updatevar":
{
let vs = (
this._socket_real.getLocalVariables() as RuntimeVariable[]
).map((v) => this.convertFromRuntime(v)) as DebugProtocol.Variable[];
response.body = {
variables: vs,
};
response.success = true;
response.command = "variables";
response.type = "response";
// let vs = (
// this._socket_real.getLocalVariables() as RuntimeVariable[]
// ).map((v) => this.convertFromRuntime(v)) as DebugProtocol.Variable[];
// response.body = {
// variables: vs,
// };
// response.success = true;
// response.command = "variables";
// response.type = "response";
this.sendResponse(response);
}
return;
case "close":
debug.stopDebugging();
this.sendResponse(response);
break;
default:
this.sendResponse(response);
break;
Expand Down
Loading

0 comments on commit 3bad570

Please sign in to comment.