Skip to content

Commit 919fc7f

Browse files
committed
Fix properties of inspected objects not being added to inspection.
1 parent 5a89c5f commit 919fc7f

6 files changed

Lines changed: 142 additions & 86 deletions

File tree

src/debugger/godot3/debug_session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class GodotDebugSession extends LoggingDebugSession {
385385
this.append_variable(va);
386386
});
387387

388-
this.add_to_inspections();
388+
this.all_scopes.forEach(scope => this.add_to_inspections(scope?.sub_values));
389389

390390
if (this.ongoing_inspections.length === 0) {
391391
this.previous_inspections = [];
@@ -421,8 +421,8 @@ export class GodotDebugSession extends LoggingDebugSession {
421421
}
422422
}
423423

424-
private add_to_inspections() {
425-
this.all_scopes.forEach((va) => {
424+
public add_to_inspections(variables: GodotVariable[]) {
425+
variables?.forEach((va) => {
426426
if (va && va.value instanceof ObjectId) {
427427
if (
428428
!this.ongoing_inspections.includes(va.value.id) &&

src/debugger/godot3/helpers.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,6 @@ export function is_variable_built_in_type(va: GodotVariable) {
3434
return ["number", "bigint", "boolean", "string"].some(x => x == type);
3535
}
3636

37-
export function build_sub_values(va: GodotVariable) {
38-
const value = va.value;
39-
40-
let subValues: GodotVariable[] = undefined;
41-
42-
if (value && Array.isArray(value)) {
43-
subValues = value.map((va, i) => {
44-
return { name: `${i}`, value: va } as GodotVariable;
45-
});
46-
} else if (value instanceof Map) {
47-
subValues = Array.from(value.keys()).map((va) => {
48-
if (typeof va["stringify_value"] === "function") {
49-
return {
50-
name: `${va.type_name()}${va.stringify_value()}`,
51-
value: value.get(va),
52-
} as GodotVariable;
53-
} else {
54-
return {
55-
name: `${va}`,
56-
value: value.get(va),
57-
} as GodotVariable;
58-
}
59-
});
60-
} else if (value && typeof value["sub_values"] === "function") {
61-
subValues = value.sub_values().map((sva) => {
62-
return { name: sva.name, value: sva.value } as GodotVariable;
63-
});
64-
}
65-
66-
va.sub_values = subValues;
67-
68-
subValues?.forEach(build_sub_values);
69-
}
70-
7137
export function parse_variable(va: GodotVariable, i?: number) {
7238
const value = va.value;
7339
let rendered_value = "";

src/debugger/godot3/server_controller.ts

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { debug, window } from "vscode";
44
import { StoppedEvent, TerminatedEvent } from "@vscode/debugadapter";
55
import { VariantEncoder } from "./variables/variant_encoder";
66
import { VariantDecoder } from "./variables/variant_decoder";
7-
import { RawObject } from "./variables/variants";
8-
import { GodotStackFrame, GodotStackVars } from "../debug_runtime";
7+
import { ObjectId, RawObject } from "./variables/variants";
8+
import { GodotStackFrame, GodotVariable, GodotStackVars } from "../debug_runtime";
99
import { GodotDebugSession } from "./debug_session";
10-
import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers";
10+
import { parse_next_scene_node, split_buffers } from "./helpers";
1111
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils";
1212
import { prompt_for_godot_executable } from "../../utils/prompts";
1313
import { subProcess, killSubProcesses } from "../../utils/subspawn";
@@ -389,7 +389,7 @@ export class ServerController {
389389
rawObject.set(prop[0], prop[5]);
390390
});
391391
const inspectedVariable = { name: "", value: rawObject };
392-
build_sub_values(inspectedVariable);
392+
this.build_sub_values(inspectedVariable);
393393
if (this.session.inspect_callbacks.has(BigInt(id))) {
394394
this.session.inspect_callbacks.get(BigInt(id))(
395395
inspectedVariable.name,
@@ -548,8 +548,68 @@ export class ServerController {
548548
stackVars.globals.push({ name: parameters[i++], value: parameters[i++] });
549549
}
550550

551-
stackVars.forEach(item => build_sub_values(item));
551+
stackVars.forEach(item => this.build_sub_values(item));
552552

553553
this.session.set_scopes(stackVars);
554554
}
555+
556+
private build_sub_values(va: GodotVariable) {
557+
const value = va.value;
558+
559+
let subValues: GodotVariable[] = undefined;
560+
561+
if (value && Array.isArray(value)) {
562+
subValues = value.map((va, i) => {
563+
const gd_var = {
564+
name: `${i}`,
565+
value: va,
566+
} as GodotVariable;
567+
568+
if(gd_var.value instanceof ObjectId)
569+
this.session.add_to_inspections([ gd_var ]);
570+
571+
return gd_var;
572+
});
573+
} else if (value instanceof Map) {
574+
subValues = Array.from(value.keys()).map((va) => {
575+
if (typeof va["stringify_value"] === "function") {
576+
const gd_var = {
577+
name: `${va.type_name()}${va.stringify_value()}`,
578+
value: value.get(va),
579+
} as GodotVariable;
580+
581+
if(gd_var.value instanceof ObjectId)
582+
this.session.add_to_inspections([ gd_var ]);
583+
584+
return gd_var;
585+
} else {
586+
const gd_var = {
587+
name: `${va}`,
588+
value: value.get(va),
589+
} as GodotVariable;
590+
591+
if(gd_var.value instanceof ObjectId)
592+
this.session.add_to_inspections([ gd_var ]);
593+
594+
return gd_var;
595+
}
596+
});
597+
} else if (value && typeof value["sub_values"] === "function") {
598+
subValues = value.sub_values().map((sva) => {
599+
const gd_var = {
600+
name: sva.name,
601+
value: sva.value,
602+
} as GodotVariable;
603+
604+
if(gd_var.value instanceof ObjectId)
605+
this.session.add_to_inspections([ gd_var ]);
606+
607+
return gd_var;
608+
});
609+
}
610+
611+
va.sub_values = subValues;
612+
613+
subValues?.forEach(this.build_sub_values.bind(this));
614+
}
555615
}

src/debugger/godot4/debug_session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class GodotDebugSession extends LoggingDebugSession {
385385
this.append_variable(va);
386386
});
387387

388-
this.add_to_inspections();
388+
this.all_scopes.forEach(scope => this.add_to_inspections(scope?.sub_values));
389389

390390
if (this.ongoing_inspections.length === 0) {
391391
this.previous_inspections = [];
@@ -421,8 +421,8 @@ export class GodotDebugSession extends LoggingDebugSession {
421421
}
422422
}
423423

424-
private add_to_inspections() {
425-
this.all_scopes.forEach((va) => {
424+
public add_to_inspections(variables: GodotVariable[]) {
425+
variables?.forEach((va) => {
426426
if (va && va.value instanceof ObjectId) {
427427
if (
428428
!this.ongoing_inspections.includes(va.value.id) &&

src/debugger/godot4/helpers.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,6 @@ export function is_variable_built_in_type(va: GodotVariable) {
3636
return ["number", "bigint", "boolean", "string"].some(x => x == type);
3737
}
3838

39-
export function build_sub_values(va: GodotVariable) {
40-
const value = va.value;
41-
42-
let subValues: GodotVariable[] = undefined;
43-
44-
if (value && Array.isArray(value)) {
45-
subValues = value.map((va, i) => {
46-
return { name: `${i}`, value: va } as GodotVariable;
47-
});
48-
} else if (value instanceof Map) {
49-
subValues = Array.from(value.keys()).map((va) => {
50-
if (typeof va["stringify_value"] === "function") {
51-
return {
52-
name: `${va.type_name()}${va.stringify_value()}`,
53-
value: value.get(va),
54-
} as GodotVariable;
55-
} else {
56-
return {
57-
name: `${va}`,
58-
value: value.get(va),
59-
} as GodotVariable;
60-
}
61-
});
62-
} else if (value && typeof value["sub_values"] === "function") {
63-
subValues = value.sub_values().map((sva) => {
64-
return { name: sva.name, value: sva.value } as GodotVariable;
65-
});
66-
}
67-
68-
va.sub_values = subValues;
69-
70-
subValues?.forEach(build_sub_values);
71-
}
72-
7339
export function parse_variable(va: GodotVariable, i?: number) {
7440
const value = va.value;
7541
let rendered_value = "";

src/debugger/godot4/server_controller.ts

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { debug, window } from "vscode";
44
import { StoppedEvent, TerminatedEvent } from "@vscode/debugadapter";
55
import { VariantEncoder } from "./variables/variant_encoder";
66
import { VariantDecoder } from "./variables/variant_decoder";
7-
import { RawObject } from "./variables/variants";
7+
import { ObjectId, RawObject } from "./variables/variants";
88
import { GodotStackFrame, GodotVariable, GodotStackVars } from "../debug_runtime";
99
import { GodotDebugSession } from "./debug_session";
10-
import { parse_next_scene_node, split_buffers, build_sub_values } from "./helpers";
10+
import { parse_next_scene_node, split_buffers } from "./helpers";
1111
import { get_configuration, get_free_port, createLogger, verify_godot_version, get_project_version, clean_godot_path } from "../../utils";
1212
import { prompt_for_godot_executable } from "../../utils/prompts";
1313
import { subProcess, killSubProcesses } from "../../utils/subspawn";
@@ -378,7 +378,7 @@ export class ServerController {
378378
const className: string = command.parameters[1];
379379
const properties: any[] = command.parameters[2];
380380

381-
// message:inspect_object returns the id as an unsigned 64 bit integer, but it is decoded as a signed 64 bit integer,
381+
// scene:inspect_object returns the id as an unsigned 64 bit integer, but it is decoded as a signed 64 bit integer,
382382
// thus we need to convert it to its equivalent unsigned value here.
383383
if(id < 0)
384384
id = id + BigInt(2) ** BigInt(64);
@@ -388,7 +388,7 @@ export class ServerController {
388388
rawObject.set(prop[0], prop[5]);
389389
});
390390
const inspectedVariable = { name: "", value: rawObject };
391-
build_sub_values(inspectedVariable);
391+
this.build_sub_values(inspectedVariable);
392392
if (this.session.inspect_callbacks.has(BigInt(id))) {
393393
this.session.inspect_callbacks.get(BigInt(id))(
394394
inspectedVariable.name,
@@ -416,8 +416,12 @@ export class ServerController {
416416
break;
417417
}
418418
case "stack_frame_vars": {
419-
this.partialStackVars.reset(command.parameters[0]);
420-
this.session.set_scopes(this.partialStackVars);
419+
const stack_var_count = command.parameters[0];
420+
this.partialStackVars.reset(stack_var_count);
421+
422+
if(stack_var_count <= 0)
423+
this.session.set_scopes(this.partialStackVars);
424+
421425
break;
422426
}
423427
case "stack_frame_var": {
@@ -556,7 +560,7 @@ export class ServerController {
556560
}
557561

558562
const variable: GodotVariable = { name, value, type };
559-
build_sub_values(variable);
563+
this.build_sub_values(variable);
560564

561565
const scopeName = ["locals", "members", "globals"][scope];
562566
this.partialStackVars[scopeName].push(variable);
@@ -566,4 +570,64 @@ export class ServerController {
566570
this.session.set_scopes(this.partialStackVars);
567571
}
568572
}
573+
574+
private build_sub_values(va: GodotVariable) {
575+
const value = va.value;
576+
577+
let subValues: GodotVariable[] = undefined;
578+
579+
if (value && Array.isArray(value)) {
580+
subValues = value.map((va, i) => {
581+
const gd_var = {
582+
name: `${i}`,
583+
value: va,
584+
} as GodotVariable;
585+
586+
if(gd_var.value instanceof ObjectId)
587+
this.session.add_to_inspections([ gd_var ]);
588+
589+
return gd_var;
590+
});
591+
} else if (value instanceof Map) {
592+
subValues = Array.from(value.keys()).map((va) => {
593+
if (typeof va["stringify_value"] === "function") {
594+
const gd_var = {
595+
name: `${va.type_name()}${va.stringify_value()}`,
596+
value: value.get(va),
597+
} as GodotVariable;
598+
599+
if(gd_var.value instanceof ObjectId)
600+
this.session.add_to_inspections([ gd_var ]);
601+
602+
return gd_var;
603+
} else {
604+
const gd_var = {
605+
name: `${va}`,
606+
value: value.get(va),
607+
} as GodotVariable;
608+
609+
if(gd_var.value instanceof ObjectId)
610+
this.session.add_to_inspections([ gd_var ]);
611+
612+
return gd_var;
613+
}
614+
});
615+
} else if (value && typeof value["sub_values"] === "function") {
616+
subValues = value.sub_values().map((sva) => {
617+
const gd_var = {
618+
name: sva.name,
619+
value: sva.value,
620+
} as GodotVariable;
621+
622+
if(gd_var.value instanceof ObjectId)
623+
this.session.add_to_inspections([ gd_var ]);
624+
625+
return gd_var;
626+
});
627+
}
628+
629+
va.sub_values = subValues;
630+
631+
subValues?.forEach(this.build_sub_values.bind(this));
632+
}
569633
}

0 commit comments

Comments
 (0)